Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    QGroupBox moving widgets up and down

    General and Desktop
    2
    2
    753
    Loading More Posts
    • 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.
    • S
      sting last edited by

      I am doing a lot of work with lists of objects and have a QGroupBox that is filled with custom widgets. I needed to be able to move them up and down in the list so I used a QGridLayout in the QGroupBox. I use the following code to do the move up. Since I am real new to Qt, I was wondering if there is a better way to do it.

      @
      void ChannelGroup::MoveToneUp(int pos){
      //setTitle("Channel*: " + QString::number(pos));
      if (pos > 0){
      QWidget prev = theLayout->itemAtPosition(pos -1, 0)->widget();
      QWidget curr = theLayout->itemAtPosition(pos, 0)->widget();
      theLayout->removeWidget(prev);
      theLayout->removeWidget(curr);
      theLayout->addWidget(curr, pos -1, 0);
      ((ToneWidget
      )curr)->setGridPos(pos -1);
      theLayout->addWidget(prev, pos, 0);
      ((ToneWidget
      )prev)->setGridPos(pos);
      }
      }
      @

      1 Reply Last reply Reply Quote 0
      • C
        ChrisW67 last edited by

        If there is only a single column of widgets then you could use a QVBoxLayout. You should only need to use takeAt() followed by insertWidget() once to move a widget up or down.

        You could also consider using a QListWidget

        1 Reply Last reply Reply Quote 0
        • First post
          Last post