PDA

View Full Version : Add widget to Scroll area widget contents



mythili
15th April 2013, 07:18
I have QWidget in QScrollArea. I have one push button in the MainWindow. I want to add QWidgets dynamically to the exixsting QWidget on pushbutton clicked. Please help me.

Mythili

Santosh Reddy
15th April 2013, 08:22
Set a layout on the QWidget (the one in QScrollArea), and add the new dynamic widgets to the layout in a slot connected the QPushButton signal clicked()

mythili
15th April 2013, 08:43
Thank u very much. Its working. I want to perform the same functions which i am doing for first QWidget which is created using ui. That functions are in seperate .cpp file.
Now I am ading this dynamic widgets in mainwindow. How to perform those functions after creating QWidget dynamically in click event.

Please help me.

Santosh Reddy
15th April 2013, 10:29
Make those functions a slots and connect to the button click signal (not event)

astodolski
16th February 2014, 20:57
Set a layout on the QWidget (the one in QScrollArea), and add the new dynamic widgets to the layout in a slot connected the QPushButton signal clicked()

Hi Santosh.

I only get one widget in the scroll area rather than multiple ones for every instance:



void MainWindow::on_actionFile_triggered()
{
QTime t = QTime::currentTime();
ctls = new Controls();
connect(this, SIGNAL(UpdateInfo(int)), ctls, SLOT(WriteInfoNumber(int)));
ui->scrollArea->setWidget(ctls);
emit UpdateInfo(t.msecsSinceStartOfDay());
}


Controls is just a row of label, progressbar and checkbox. The signal emitted updates the label. As I said, there is only one row for every call of the method. The layout is made in the designer.