How to get the widget from QScrollArea with the index of widget?
-
How to get the widget from QScrollArea with the index of the widget in scroll area? I have the index of widget and want to delete it from the scrollArea. But I can't find any solution.
@Mikiqueen
What index? Do you mean you have added widgets to a layout and want to remove one of them?Or, every
QObject
can usefindChild()
to try to find a particular child. is that relevant? -
How to get the widget from QScrollArea with the index of the widget in scroll area? I have the index of widget and want to delete it from the scrollArea. But I can't find any solution.
@Mikiqueen QScrollArea only holds one widget so there is no index. That widget can have children, but their order is unspecified. A widget can have layout set and you can get a layout element with specified index. From layout element you can get a widget it hosts if it has any.
Whether that's what you want or not I couldn't tell you. You didn't say where that index you have comes from.
-
@Mikiqueen QScrollArea only holds one widget so there is no index. That widget can have children, but their order is unspecified. A widget can have layout set and you can get a layout element with specified index. From layout element you can get a widget it hosts if it has any.
Whether that's what you want or not I couldn't tell you. You didn't say where that index you have comes from.
@Chris-Kawa I get the index from the order I add widget to scroll area (I track and store the index of widget added order). Thank you so much I use .itemAt(index) to locate the widget.
-
@Chris-Kawa I get the index from the order I add widget to scroll area (I track and store the index of widget added order). Thank you so much I use .itemAt(index) to locate the widget.
@Mikiqueen said in How to get the widget from QScrollArea with the index of widget?:
I get the index from the order I add widget to scroll area (I track and store the index of widget added order).
@Chris-Kawa said in How to get the widget from QScrollArea with the index of widget?:
@Mikiqueen QScrollArea only holds one widget so there is no index.
Since you can't add multiple widgets to a QScrollArea
The QScrollArea class provides a scrolling view onto another widget
A scroll area is used to display the contents of a child widget within a frame. [...] The child widget must be specified with setWidget()
void QScrollArea::setWidget(QWidget *widget)
Sets the scroll area's widget.
In view of the above (i.e. one widget) don't you think you had better show (a minimal example of) how you add all these widgets:
I get the index from the order I add widget to scroll area (I track and store the index of widget added order).
I use .itemAt(index) to locate the widget
QScrollArea
does not have anyitemAt()
. -
@Mikiqueen said in How to get the widget from QScrollArea with the index of widget?:
I get the index from the order I add widget to scroll area (I track and store the index of widget added order).
@Chris-Kawa said in How to get the widget from QScrollArea with the index of widget?:
@Mikiqueen QScrollArea only holds one widget so there is no index.
Since you can't add multiple widgets to a QScrollArea
The QScrollArea class provides a scrolling view onto another widget
A scroll area is used to display the contents of a child widget within a frame. [...] The child widget must be specified with setWidget()
void QScrollArea::setWidget(QWidget *widget)
Sets the scroll area's widget.
In view of the above (i.e. one widget) don't you think you had better show (a minimal example of) how you add all these widgets:
I get the index from the order I add widget to scroll area (I track and store the index of widget added order).
I use .itemAt(index) to locate the widget
QScrollArea
does not have anyitemAt()
.