Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-113723

Incorrect toolbar spacing inherited from stylesheets

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.4.2, 6.4.3, 6.5.0
    • Widgets: Style Sheets
    • None
    • Windows

    Description

      The spacing between buttons of the class inherited from the QToolBar can't be controlled through the stylesheets when it has been already defined for QToolBar class.

      Having stylesheet with next code:

      QToolBar{ spacing: 2px;}
      CustomToolBar{ spacing: 20px; background: white;} 

      produces the next result:

       

      Both toolbars have spacing equal to 2px despite that it is set to 20px for objects CustomToolBar class. At the same time, the background is correctly set to white.

      The problem could be that QToolBarLayout::updateMarginAndSpacing() is called before render rules for CustomToolBar are initialized.

      A temporary workaround could be sending StyleChange event to the custom toolbar after handling Polish event.

      bool CustomToolBar::event(QEvent* event)
      {
          // Code fixing the issue
          const bool res = QToolBar::event(event);
      #if 1
          if (event->type() == QEvent::Polish)
          {
              QEvent e(QEvent::StyleChange);
              QCoreApplication::sendEvent(this, &e);
          }
      #endif
          return res;
      } 

      Results after applying the fix

      The minimal project reproducing the bug is attached.

      Also if style of the class has a dynamic property then QToolBarLayout::updateMarginAndSpacing() needs to be called after the change of that property:

      CustomToolBar[CustomProperty=true]
      {
          spacing: 20px;
          background: yellow;
      }  

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            medyakovvit Vitaly
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes