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. Qlistwidget move up and down?

Qlistwidget move up and down?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 2.1k Views 1 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.
  • A Offline
    A Offline
    anil_arise
    wrote on last edited by
    #1

    For Down List:

    QListWidgetItem *currentItem = ui->listWidget->takeItem(currentIndex);
    ui->listWidget->insertItem(currentIndex+1, currentItem);
    ui->listWidget->setCurrentRow(currentIndex+1);

    it move the items but remove the widget of currentIndex why ?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You mean you have widgets on the items via setItemWidget ?

      A 1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3

        From Qt 5.13 onward you can use ui->listWidget->model()->moveRow(QModelIndex(),currentIndex,QModelIndex(),currentIndex+1);

        https://doc.qt.io/QT-5/qabstractitemmodel.html#moveRow

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        2
        • mrjjM mrjj

          Hi
          You mean you have widgets on the items via setItemWidget ?

          A Offline
          A Offline
          anil_arise
          wrote on last edited by anil_arise
          #4

          @mrjj yes ;
          setItemWidget(QListWidgetItem *item, QWidget *widget);

          mrjjM VRoninV 2 Replies Last reply
          0
          • A anil_arise

            @mrjj yes ;
            setItemWidget(QListWidgetItem *item, QWidget *widget);

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

            Hi
            I think you have to handle that yourself.
            Try to call
            https://doc.qt.io/qt-5/qtreewidget.html#itemWidget
            on currentItem and see if it still has it widget when you take it out.

            1 Reply Last reply
            0
            • A anil_arise

              @mrjj yes ;
              setItemWidget(QListWidgetItem *item, QWidget *widget);

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              @anil_arise said in Qlistwidget move up and down?:

              yes ;
              setItemWidget(QListWidgetItem *item, QWidget *widget);

              REPENT!!!

              Why are you using this?

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              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