Unsolved QWidget add to QScrollArea
-
Hello,
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 ? -
@jondoe
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 theQScrollArea
?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. -
@JonB said in QWidget add to QScrollArea:
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.
-
@jondoe
So you will write "copy" code to create the new widgets from the yellow widget you have downward into its content. There is (deliberately) noQWidget
copy constructor, so you will create new widgets vianew QWidget/QLabel/QOushbutton
and 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 theQObject::findChildren
overloads inherited byQWidget
to discover all children programmatically.