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

adjustSize() is not up to date when widget is within a QScrollArea

    XMLWordPrintable

Details

    Description

      if widget is not set to be resizable in the scroll area, and child widgets are being added to it in a layout, then adjustSize will get a wrong size and make it too small.

      Following snippet demonstrates the problem:

      #include <QtGui>

      class CustomWidget: public QWidget{
      Q_OBJECT

      public:
      CustomWidget(QWidget *parent = 0, Qt::WindowFlags f = 0) : QWidget(parent, f)

      { layoutB = new QVBoxLayout(); setLayout(layoutB); }

      public slots:
      void addButton()

      { layoutB->addWidget( new QPushButton("Sample") ); adjustSize(); } private: QVBoxLayout *layoutB; }

      ;

      #include "main.moc"

      int main(int argc, char *argv[])
      {
      QApplication app(argc, argv);

      QWidget *mainWidget = new QWidget();
      QVBoxLayout layoutA;
      mainWidget->setLayout(&layoutA);
      QPushButton *pushButton = new QPushButton("Add a widget");
      layoutA.addWidget(pushButton);
      QScrollArea *scrollArea = new QScrollArea(mainWidget);
      CustomWidget *custom = new CustomWidget(scrollArea);
      scrollArea->setWidget(custom);
      layoutA.addWidget(scrollArea);

      QObject::connect( pushButton, SIGNAL(pressed()),
      custom, SLOT(addButton()) );

      mainWidget->resize( 300, 400 );
      mainWidget->show();

      return app.exec();
      }

      Attachments

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

        Activity

          People

            ntg Pierre Rossi
            ntg Pierre Rossi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes