简体   繁体   中英

Qt getting nearby widgets of type around a widget?

I am trying to stack rectangular widgets one after another over a line edit and for each one, I need to know the position of the one to the left, so I can push the new one to the right, so they are next to each other instead of one over another. Is there a way to get a widget of the same type next to another widget, so I can check its coordinates and size and move the new one to the right respectively?

If they are top-level widgets, there is. But if not, you'll need to tag them somehow and then search for them. Check for these function in QApplication :

QWidget *   topLevelAt(const QPoint & point)
QWidget *   topLevelAt(int x, int y)
QWidgetList topLevelWidgets()

and in QObject (from which QWidget inherits):

T   findChild(const QString & name = QString()) const
QList<T>    findChildren(const QString & name = QString()) const
QList<T>    findChildren(const QRegExp & regExp) const

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM