Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Guest last edited by
I have a container widget that contains only a vertical layout, to which empty push buttons are added. The widget works just fine if I add it to a parent widget (1)
But when I set the container widget to the scroll area inside the parent widget, nothing really shows when I add buttons (2)
If I add a single button to the container widget in its constructor, then more buttons do show but the layout is all wrong and the scroll area is not really working at all (3)
@ mainLayout = new QVBoxLayout(this);
addOne = new QPushButton("Add one", this);
scrollArea = new QScrollArea(this);
container = new Container(this); scrollArea->setWidget(container); mainLayout->addWidget(addOne); mainLayout->addWidget(scrollArea);
setLayout(mainLayout); connect(addOne, SIGNAL(clicked()), this, SLOT(addOneSlot()));@
andre last edited by
You need to add stuff not to the QScrollArea itself, but to the widget returned by widget()
Guest last edited by
^^I didn't really get what you mean by that.
I do not add anything to the scroll area itself, the content of scrollArea is set by setWidget(), and extra stuff I add to the layout that is inside the container widget.
But even without adding anything, just setting the container widget to the scroll area doesn't work correctly, the widget itself is being rendered just ok when put in a layout, but when I put it inside the scroll area it doesn't fill it, instead occupies just the upper left corner as in the screenshot above.
Adding stuff to the container widget works just fine, putting the container inside the scroll area is problematic.
What is also odd is without that one initial push button inside container, the addOneSlot doesn't seem to add anything, or actually IT DOES ADD a push button, as dumpObjectTree() indicates, it is more like the container widget itself is not added to the scroll area at all if it is just one empty layout with nothing in.
elmigranto last edited by
[quote author="Deleted Member # 269f" date="1333018338"]^^I didn't really get what you mean by that.[/quote]Probably something like this (worked for me):