How to dynamically insert a custom widget into a scroll area
-
wrote on 15 Feb 2014, 03:07 last edited by
I have a custom widget, built in designer, made up of a row of label, progress bar, check box. In the main form, I have a scroll area, also created in the designer. I want to know how to effectively dynamically add the custom widget as as rows in the scroll area.
MainWindow.cpp
@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "ui_Controls.h"MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_actionE_xit_triggered()
{
QApplication::quit();
}void MainWindow::on_actionFile_triggered()
{
int i = ui->verticalLayout->count();ctls = new Controls();
QHBoxLayout* hblayout = new QHBoxLayout();
hblayout->addWidget(ctls);
QWidget* window = new QWidget;
window->setLayout(hblayout);
window->show();ui->verticalLayout->addWidget(window);
}
@The Main Window grows downward rather than a vertical scroll bar appearing.
-
Hi,
You need to set a widget on the QScrollArea containing a QVBoxLayout. Then add your newly created widget with to that layout.
Hope it helps
-
wrote on 18 Feb 2014, 12:36 last edited by
[quote author="SGaist" date="1392499717"]Hi,
You need to set a widget on the QScrollArea containing a QVBoxLayout. Then add your newly created widget with to that layout.
Hope it helps[/quote]
I changed the approach as to how to display the widget and instead use a QListWidget. The thread is "here":http://qt-project.org/forums/viewthread/38539/. Still doesn't work
-
It's not exactly the same concept then
-
wrote on 18 Feb 2014, 21:02 last edited by
No less troubling though. Can you offer assistance?
-
wrote on 18 Feb 2014, 21:23 last edited by
I think QListWidget is rather limited. I would say use QListView if you are going to endup with lots of items in your scroll area and are prepared write your own paint delegate.
It really can't get any easier then using a VerticalGridLayout and using its addWidget() method
-
wrote on 18 Feb 2014, 21:40 last edited by
[quote author="DBoosalis" date="1392758583"]I think QListWidget is rather limited. I would say use QListView if you are going to endup with lots of items in your scroll area and are prepared write your own paint delegate.
It really can't get any easier then using a VerticalGridLayout and using its addWidget() method
[/quote]
Got an example? I only know of QGridLayout
-
wrote on 18 Feb 2014, 22:11 last edited by
Documentation is a good place to start.
-
wrote on 19 Feb 2014, 03:55 last edited by
[quote author="DBoosalis" date="1392761494"]Documentation is a good place to start. [/quote]
I can't find any documentation on VerticalGridLayout. That's why I asked for an example. I wanted to see an example how it can't get any easier. BTW VerticalGridLayout is part of Java.
-
There's no vertical grid layout, you have "QVBoxLayout":http://qt-project.org/doc/qt-5/qvboxlayout.html to layout things vertically. You still can use a QGridLayout if you want, you just need to add rows
1/10