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

surprising layout margins and spacing for QBoxLayout on macOS

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.2
    • None
    • macOS 12
    • macOS

    Description

      I found that layouts inherited from QBoxLayout have artificial margins which are not affected/removable by setting setContentsMargins().

      Check the following code:

      #include <QApplication>
      #include <QPushButton>
      #include <QVBoxLayout>
      #include <QWidget>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QWidget w;
      
          auto layout = new QVBoxLayout();
          w.setLayout(layout);
      
          auto layout2 = new QVBoxLayout();
          layout2->setContentsMargins(0, 0, 0, 0);
          layout->addLayout(layout2);
      
          auto b1 = new QPushButton("B1");
          layout2->addWidget(b1);
      
          auto b2 = new QPushButton("B2");
          layout2->addWidget(b2);
      
          auto b3 = new QPushButton("B3");
          layout->addWidget(b3);
      
          auto b4 = new QPushButton("B4");
          layout->addWidget(b4);
      
          w.show();
          return a.exec();
      }
      

      There are four buttons B1-B4. The first two are in an inner layout, which has contents margins equal to 0. The other two are in outer layout. On Windows and Linux, this shows a widget with four equal and equally spaced buttons.

      On macOS however this shows buttons B1 and B2 somehow smaller and with spacing between B2 and B3 being bigger than other spacings. See the attached picture.

      This is so surprising behaviour that I consider this to be a bug.

      I also found that there are some #ifdef Q_OS_MAC in qboxlayout.cpp which I blame to be at fault. I think that layouting should be platform-agnostic.

      Attachments

        1. screenshot-1.png
          screenshot-1.png
          31 kB
        2. screenshot-2.png
          screenshot-2.png
          30 kB

        Issue Links

          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
              vladimir.kraus Vladimir Kraus
              Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes