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

QLabel with word wrap makes unable to decrease parent items size

    XMLWordPrintable

Details

    • Windows
    • 4d4eb11fe340bf0b3a1ce0caae62d9319bf941cf (qt/qtbase/dev) d9697f9f5df2b555997d66695b57f926908057ee (qt/qtbase/6.1)

    Description

      Consider the following example:

      class TestWidget: public QWidget
      {
      public:
          QSize sizeHint() const
          {
              return QSize(300, 300);
          }
          QSize minimumSizeHint() const
          {
              return QSize(100, 100);
          }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QDialog dialog;
          auto dialogLayout = new QVBoxLayout(&dialog);
      
          auto mainWidget = new QWidget;
          auto mainLayout = new QVBoxLayout(mainWidget);
          dialogLayout->addWidget(mainWidget);
      
          auto label = new QLabel("Test");
          label->setWordWrap(true);
          mainLayout->addWidget(label);
      
          auto widget1 = new TestWidget;
          widget1->setStyleSheet("QWidget {background-color:red;}");
          auto scroll1 = new QScrollArea;
          scroll1->setWidget(widget1);
          scroll1->setWidgetResizable(true);
          mainLayout->addWidget(scroll1);
      
          auto widget2 = new TestWidget;
          widget2->setStyleSheet("QWidget {background-color:green;}");
          auto scroll2 = new QScrollArea;
          scroll2->setWidget(widget2);
          scroll2->setWidgetResizable(true);
          mainLayout->addWidget(scroll2);
      
          dialog.show();
      
          return a.exec();
      }
      

      On Windows we cannot decrease the window size and looks like for widgets minimumSizeHint became equal to sizeHint. On Linux works fine. Check Text_no_Resize.gif

      I also see this message in the console on application start:

      QWindowsWindow::setGeometry: Unable to set geometry 640x480+1731+706 (frame: 662x536+1720+661) on QWidgetWindow/"QDialogClassWindow" on "\\.\DISPLAY1". Resulting geometry: 640x699+1731+706 (frame: 662x755+1720+661) margins: 11, 45, 11, 11 minimum size: 165x309 MINMAXINFO maxSize=0,0 maxpos=0,0 mintrack=187,365 maxtrack=0,0)
      

      If we either remove the wordWrap or remove the intermediate mainWidget item we can shrink widgets: Text_Resize.gif
      Size hints looks reasonable:Size_Hints.gif
      If wrap both widgets (red and green) with their scroll areas into a splitter, we can resize widgets but still can't shrink the window: Splitter.gif

      Attachments

        1. Label_Text_Update.gif
          Label_Text_Update.gif
          416 kB
        2. qtbug92599.zip
          2 kB
        3. Size_Hints.gif
          Size_Hints.gif
          658 kB
        4. Splitter.gif
          Splitter.gif
          362 kB
        5. Text_no_Resize.gif
          Text_no_Resize.gif
          373 kB
        6. Text_Resize.gif
          Text_Resize.gif
          342 kB
        For Gerrit Dashboard: QTBUG-92599
        # Subject Branch Project Status CR V

        Activity

          People

            smd Jan Arve
            nkrupenko.nvidia Nikita Krupenko
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes