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. QGroupBox moving widgets up and down

QGroupBox moving widgets up and down

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 895 Views
  • 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 Offline
    S Offline
    sting
    wrote on last edited by
    #1

    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
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      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
      0

      • Login

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