QWidget add to QScrollArea
I have QScrollArea and QWidget ( in label and pushbutton ).
When I clicking to red push button i want add yellow widget to QScrollArea with label and pushbuttons. How can I do this ?
From your screenshot: do you mean you want to add a new yellow widget (with *image + pushbutton) just like the one you have on the right, or do you mean you want to move the existing widget (+ content) at the right so that it is now inside the
Either way you will be using https://doc.qt.io/Qt-5/qscrollarea.html#setWidget to set the
QScrollArea's widget to your yellow widget (maybe plus layout), it's only a question of whether you create a copy of your yellow one or make it your existing one.
want to add a new yellow widget (with *image + pushbutton) just like the one you have on the right
I want to add a new yellow widget (with *image + pushbutton) just like the one I have on the right.
So you will write "copy" code to create the new widgets from the yellow widget you have downward into its content. There is (deliberately) no
QWidgetcopy constructor, so you will create new widgets via
new QWidget/QLabel/QOushbuttonand it is your job to copy whatever attributes are currently on the old widgets into the new widgets, e.g. color, size etc. (e.g. see https://www.qtcentre.org/threads/26546-Deep-copy-of-widget-hierarchy for confirmation that this is the way to go) If you don't want to have to know what the children are to start with, you can use one of the
QObject::findChildrenoverloads inherited by
QWidgetto discover all children programmatically.