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. Reordering ListWidgetItem Items.

Reordering ListWidgetItem Items.

Scheduled Pinned Locked Moved General and Desktop
12 Posts 2 Posters 3.5k 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.
  • R Offline
    R Offline
    Razan
    wrote on last edited by
    #1

    Hello,

    I'm a beginner at qt.
    I’m doing a kind of ranking using QListWidget, I want to be able to reorder some labels. I have used QListWidget as my list and added to it the QListWidgetItem and Qlabel. I enabled the drag and drop property for it. I'm able to reorder the list but I can not get the reordering result.
    Each time after reordering when I read the QListWidget I get the initial order. I do not know how can I get the reordering result after the user reorders these labels, and is it possible even if I do it in this simple way.

    How can I get the reordering information form GUI.

    Thank you.

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

      Hi and welcome to devnet,

      Do you mean get a string list with the current content of the QListWidget ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Razan
        wrote on last edited by
        #3

        Hey,

        Yes I want to get the Qlabel text each time I do reordering.
        I want to check the result of the reordering by checking the text on each label, which should be changed each time.
        After the label reordering I check the list item again, but the problem is I can only get the initial order.

        This is the code:
        @

        for (int i = 0 ; i< list->count(); i++){

        QListWidgetItem* item =  dynamic_cast <QListWidgetItem*>(list->item(i));
        QLabel* label = dynamic_cast<QLabel*> (list->itemWidget(item));
        
        std::cout<<"The text after reordering :"<<label->text().toStdString()<<std::endl;
        

        }

        @

        Thank you,

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          There's something strange here, why are you casting to QLabel ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Razan
            wrote on last edited by
            #5

            Because I want to read the text from that label,
            I don't know if I did it in a wrong way, I'm a beginner so I do not know if it should be done in different way.

            It will be nice if you can help me.
            Thank you in advance.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              QListWidget doesn't create QLabel for its items. You can get the text directly from the item.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Razan
                wrote on last edited by
                #7

                okay I deleted the Qlabel.
                But the problem is still there. I'm wondering why each after I do reordering, and I click proceed the Qlistwidget has the initial ordering, and it does not update its items according to the new reordering from the GUI.

                @
                void Gui::qtReactOnProceed(){

                for (int i = 0 ; i< list->count(); i++){
                QListWidgetItem* item = dynamic_cast <QListWidgetItem*>(list->item(i));
                std::cout<<"The row:"<<item->text().toStdString()<<std::endl;
                }
                }
                @

                Actually I do not know how the DragandDropMode updates the Qlistwidget, is it done by default.

                Thank you again.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  How are you doing the reordering ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    Razan
                    wrote on last edited by
                    #9

                    I’m reordering By using the drag and drop mode for the listwidget.
                    I have created the listwidget then enabled the drag and drop mode for it.

                    After the user do reordering he clicks a button so in that action I’m reading the list again to check its items "new reorder for the items".

                    Is that the right way.

                    Does the Gui refresh itself, or I have to add the list again to Gui each time I do reordering.

                    I hop you a clear get an idea about what I trying to do.
                    Thank you again.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Can you show the code where you setup the drag and drop behavior ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        Razan
                        wrote on last edited by
                        #11

                        Hello,

                        Thank you,
                        I could solve the problem, it was not in the qlistwidget, actually the qlistwidget with dragnaddrop mode works fine.

                        But the problem was in calling the function, it was called many times and in that case more than one list are created, and added on the top of each other, accordingly I had incorrect result from the list.

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          You're welcome !

                          Nice you found out and thanks for sharing.

                          Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          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