Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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


  • Moderators

    @zloi_templar you can call raise() in the widget, that will raise it to the top of the stack/paint order


  • Moderators

    @zloi_templar you can call raise() in the widget, that will raise it to the top of the stack/paint order


  • Lifetime Qt Champion

    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 ?



  • @J-Hilk ahaha, ty, it's work) so simple and beauty)



  • @mrjj
    That it wont react to hovering the mouse over it or ?
    No, it's don't over other square frames
    Ty, raise() is worked!


  • Lifetime Qt Champion

    @zloi_templar
    ok. so it was the Z order of the widgets.
    Thank you


Log in to reply