Unsolved Find QLayout within QGridLayout
-
@peter-70
To find a "parent layout" of a layout, which is what you want, is not straightforward like it is for parent widget. Read https://stackoverflow.com/questions/2409539/getting-parent-layout-in-qt for the solution.Ahh, you want it the other way round, you want the find a child layout in a
QGridLayout
. So http://doc.qt.io/qt-5/qlayout.html#indexOf-1. (Assuming it's a direct child layout, else you have to search recursively.) -
QGridLayout::getItemPosition gives me some more informations which I need: http://doc.qt.io/qt-5/qgridlayout.html#getItemPosition.
But it does not accept an other layout as parameter -
-
@JonB
probably the fact that it does not include other Layouts ? ;)int QLayout::indexOf(QLayoutItem *layoutItem) const Searches for layout item layoutItem in this layout (**not including child layouts**). Returns the index of layoutItem, or -1 if layoutItem is not found. This function was introduced in Qt 5.12.
this should work, however it's untested
for(int i(0); i < container->count(); i++) { QLayout layout* = qobject_cast<QLayout*>(container->itemAt(i)); if(layout) qDebug() << "Layout found"; }
-
Oh sorry! You're absolutely right, my fault! The problem is only, I have a deprecated version of Qt:
Qt Creator 4.6.2
Based on Qt 5.11.1 (Clang 8.0 (Apple), 64 bit)
Built on Jun 18 2018 11:51:56
From revision 1ddfb443b6So I must renew it and the problem should be away.
Thank you!
-
probably the fact that it does not include other Layouts ? ;)
Hmm, I thought the docs meant it does include direct child layouts but not "grand-"child layouts. I'm obviously not quite understanding what
QLayout::indexOf()
is looking at, or I'm not understand what aQLayoutItem
is...? [In effect I thoughtQLayout::indexOf()
is doing your loop already itself, I thought it is returning all layouts added viaQGridLayout::addLayout
.] -
@JonB
you may be right, I can't test it, as I'm not using 5.12, it's still to buggy! -
@J.Hilk: I know some problems with the Qt software development, but at the moment I dont know what do you mean? What is buggy?
-
-
@peter-70 said in Find QLayout within QGridLayout:
Qt Creator 4.6.2
Based on Qt 5.11.1 (Clang 8.0 (Apple), 64 bit)This is not necessarily the Qt version you're using, this is the Qt version used to build QtCreator. You should rather check what Qt version you actually installed.
-
@peter-70
In my opinion 5.12.0 was rushed to be released during the QtWorldSummit.I'm unable to port any of my projects from 5.11.3 to 5.12 without major changes in the code base for workarounds. Some issues I'm unable to fix without modifying the QtLibary itself.
I don't have the time and/or knowledge for that. So I'm staying on 5.11.3 until at least 5.12.1 if not later, it's a LTS-version so bugfixes will keep on coming I asume ;-)
-
@J.Hilk Oh, that's silly :-(
Thanks for your advice!