Re: QGridLayout: Getting the list of QWidget added
Suppose I have something like:
What is the method that I can use to get the list of the added QWidgets ?
Something like the imaginary "getAddedWidgets()" below:
Code:
QList<QWidget*> addedWidgets = layout.getAddedWidgets();
Q_ASSERT( addedWidgets.size() == 2 );
Added after 1 29 minutes:
The example code below shows how you could iterate over each item:
Code:
// add 3 items to layout
// sanity checks
Q_ASSERT(layout.count() == 3);
Q_ASSERT(layout.itemAt(0));
Q_ASSERT(layout.itemAt(1));
Q_ASSERT(layout.itemAt(2));
Q_ASSERT(layout.itemAt(3) == NULL);
// iterate over each, only looking for QWidgetItem
for(int idx = 0; idx < layout.count(); idx++)
{
item
->widget
()->hide
(); <
-- widget
() will cast you a
QWidget! }
Re: QGridLayout: Getting the list of QWidget added
dynamic_cast should be avoided when dealing with QObjects.
Use qobject_cast instead.
Re: QGridLayout: Getting the list of QWidget added
Quote:
Originally Posted by
tbscope
dynamic_cast should be avoided when dealing with QObjects.
Use qobject_cast instead.
why so? is dynamic_cast is slower than qobject_cast? I do have RTTI always in my compiler, so given that, can you plz elaborate?