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

[Reg 6.8->6.9.0] Stylesheet on QPushButton makes spacing smaller

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.9.0 Beta2, 6.10.0 FF
    • Widgets: Style Sheets
    • None
    • macOS 15.2
    • macOS

    Description

      Commit aa341ecca816e3503a834ffde0ec6cb817139427 changes how spacing in layouts works with QPushButtons that have a style sheet applied (this style sheet does not need to change anything, it just needs to be there to convert the OS-native button to a Qt one).

      Having two QPushButtons on top of each other in a QVBoxLayout, there is now less space between the buttons. When setting the layout spacing to 0, they overlap (instead of having zero spacing).

      Reverting said commit brings the behavior back to what it was before.
      I've attached images to show the difference (the ones prefixed "dev" are current dev branch behavior, the ones "revert" are with the commit reverted).

      Here's a (hopefully minimal) reproducer (also attached as CMake project):

      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          a.setStyleSheet(R"(
      QPushButton {
          border-radius: 0px;
      }
      
      QPushButton:hover {
          background-color: #4d4d4d;
      }
          )");
      
          QWidget w;
          auto lay = new QVBoxLayout(&w);
          lay->addWidget(new QPushButton("Text"));
          lay->addWidget(new QPushButton("Also Text"));
          lay->setSpacing(0);
          w.show();
          return a.exec();
      }
      

      I observed this on macOS, and am unable to test on other operating systems.

      Attachments

        1. revert-zero-spacing.png
          revert-zero-spacing.png
          13 kB
        2. revert-normal-spacing.png
          revert-normal-spacing.png
          13 kB
        3. QTBUG-Sample.zip
          2 kB
        4. qtbase-10-20-52.diff
          0.9 kB
        5. dev-zero-spacing.png
          dev-zero-spacing.png
          12 kB
        6. dev-normal-spacing.png
          dev-normal-spacing.png
          13 kB
        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
            sebastianbeckmann Sebastian Beckmann
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes