How to change QFrame children order
-
Hello, i have QMainWindow with stretched to full screen QFrame (QFrame has no layout) ui->frame.
Then i create a lot of multi-colored frames in the form of squares
QFrame *fr = new QFrame(ui->frame);
An algorithm for dragging these squares in shape has been implemented.
What is my problem: when i drag last created frame, everything works well, it overlaps all frames when you hover it on them.
Penultimate hover all, but not the last, etc. First created frame doesn't hover anything.
I wanted to try changing the order of the childs, but this methods is const
for(int i=0; i<ui->frame->children().count(); i++) if(ui->frame->children().at(i)->objectName()==fr->objectName()) { ui->frame->children().move(i, ui->frame->children().count()); break; }
What can i do?
I also tried change the parent
bool MainWindow::eventFilter(QObject *watched, QEvent *e) { QMouseEvent *mouseEvent; if(e->type() == QEvent::MouseMove) { if(watched->objectName().startsWith("pfr")) { fr=static_cast<QFrame*>(watched); fr->setCursor(Qt::PointingHandCursor); QRect r = fr->geometry(); fr->setParent(0); fr->setParent(ui->frame); fr->setGeometry(r); fr->show(); } } }
But then frame stopped drag, i lose signal on event
-
@zloi_templar you can call raise() in the widget, that will raise it to the top of the stack/paint order
-
Hi
Do you mean you want to control the z order ?
QWidget::lower() / QWidget::raise() / QWidget::stackUnder()
can be used for that.First created frame doesn't hover anything.
What does this mean ?
That it wont react to hovering the mouse over it or ? -
@zloi_templar
ok. so it was the Z order of the widgets.
Thank you