[Interest] Can I update contents in QScrollArea dynamically?

Tony Rietwyk tony at rightsoft.com.au
Thu Nov 15 13:50:50 CET 2012


Hi Li, 

 

This seems to be a common mistake - adding widgets directly to the
QScrollArea as child widgets, rather than using its setWidget.   Read the
docs - they are very clear.  

 

Tony.

 

 

 

From: interest-bounces+tony=rightsoft.com.au at qt-project.org
[mailto:interest-bounces+tony=rightsoft.com.au at qt-project.org] On Behalf Of
Zhang, Li
Sent: Friday, 2 November 2012 12:04 AM
To: interest at qt-project.org
Subject: [Interest] Can I update contents in QScrollArea dynamically?

 

Hi All,

 

I want to use a QScrollArea as a container of several buttons[or other
components], and then I need to replace all of these buttons with new(also
the amount of buttons is different). 

Current, I just  add buttons to the QScrollArea, but can not remove all of
them and update with new buttons...

    groupBox = new QGroupBox(ui->GCultureDetailedScrollArea);

    groupLayout = new QGridLayout(groupBox);

    groupBox->setLayout(groupLayout);

    groupLayout->setVerticalSpacing(15);

    groupLayout->setHorizontalSpacing(10);

 

    for(int i = 0; i < 50; i++){

< div>

        for(int j = 0; j < 3; j++){

            QString buttonName = QString("button%1").arg(i+1);

            QPushButton *pbutton = new QPushButton(buttonName);

            //pbutton->resize(130, 40);

            pbutton->setMinimumWidth(140);

            pbutton->setMinimumHeight(40);

            pbutton->setStyleSheet("\

                                   QPushButton{\

                                    border-image:
url(./pictures/button_groupactivities.png);\

      &nb sp;                            }\

                                   QPushButton:pressed {\

                                    border-image:
url(./pictures/button_groupactivities_clicked.png);\

                                   }\

                                   ");

            groupLayout->addWidget(pbutton, i, j);

        }

    }

 

So now how can I remove all of buttons in groupLayout an d add new ones.

 

Anyone can give some suggestions?   Thanks in advance!

 

--

 Best Regards,

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121115/ba08ad7c/attachment.html>


More information about the Interest mailing list