Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to change QFrame children order
Forum Updated to NodeBB v4.3 + New Features

How to change QFrame children order

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zloi_templar
    wrote on last edited by zloi_templar
    #1

    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

    J.HilkJ 1 Reply Last reply
    0
    • Z zloi_templar

      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

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

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


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      Z 1 Reply Last reply
      4
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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 ?

        Z 1 Reply Last reply
        3
        • J.HilkJ J.Hilk

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

          Z Offline
          Z Offline
          zloi_templar
          wrote on last edited by
          #4

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

          1 Reply Last reply
          1
          • mrjjM mrjj

            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 ?

            Z Offline
            Z Offline
            zloi_templar
            wrote on last edited by
            #5

            @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!

            mrjjM 1 Reply Last reply
            0
            • Z zloi_templar

              @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!

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved