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 do I "move" an item from one QListWidget to another?
Forum Updated to NodeBB v4.3 + New Features

How do I "move" an item from one QListWidget to another?

Scheduled Pinned Locked Moved General and Desktop
21 Posts 7 Posters 18.6k 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.
  • G Offline
    G Offline
    goetz
    wrote on last edited by
    #11

    takeWidgetItem only removes the widget of the item which was set with setWidgetItem before. It does not remove the QListWidgetItem itself from the view; this is achieved with takeItem.

    You can safely transfer a QListWidgetItem from on list widget to another:

    @
    void ListManager::on_addButton_clicked()
    {
    if( ui->leftList->count() == 0 )
    // nothing to transfer...
    return;

    QListWidgetItem *widget = ui->leftList->takeItem( ui->leftList->currentRow() );
      ui->rightList->addItem(widget);
    }
    @

    This obviously works only with single selection mode of the list widget. For a multi-item selection mode you will have to do some more work.

    http://www.catb.org/~esr/faqs/smart-questions.html

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jonathan
      wrote on last edited by
      #12

      Thanks Volker. This works and is reasonably "clean" code.

      I still feel the more obvious "remove from left/add to right" approach should work.

      Researching the model-view alternative is on my to-do list ;o)

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #13

        Oh, you still do remove from the left and add to the right. The only difference is that you save yourself from creating a new item with new for the right view and delete item left over from the left view. Instead you just recycle the old one.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #14

          That sounds like a better alternative than recreate it, gives less memory fragmentation... :-)

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dangelog
            wrote on last edited by
            #15

            [quote author="Gerolf" date="1292773031"]That sounds like a better alternative than recreate it, gives less memory fragmentation... :-)[/quote]

            If you do care about memory framgentation Qt is the wrong toolkit for you :)

            Software Engineer
            KDAB (UK) Ltd., a KDAB Group company

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #16

              Not always. If you need a UI toolkit that is perhaps cross platform, what else to use? wxWidgets? it's different, but better? I think no. And you can reduce the fragemntation but just don't use some things. The software we are creating is running 24/7 normally. So you should look at such things a bit, and where you can prevent, you should...

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • J Offline
                J Offline
                Jonathan
                wrote on last edited by
                #17

                I successfully used the same "takeItem()" idea to remove an item from the right list and reinsert it at an index one above or one below its old location (ie to reprioritise the item in the list).

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  Jonathan
                  wrote on last edited by
                  #18

                  Perhaps the biggest hole in the Qt environment is the lack of integrated analysis tools, eg for memory leaks, performance analysis. The only option AFAIK is Valgrind.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #19

                    For linux, you use valgrin, for windows, I know no free solution, only commercial ones.
                    But for those tools, ther are already threads "here":http://developer.qt.nokia.com/forums/viewthread/2248 and "here":https://developer.qt.nokia.com/forums/viewthread/1924

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      vcsala
                      wrote on last edited by
                      #20

                      We had a thread "here":http://developer.qt.nokia.com/forums/viewthread/1924 which had discussed the such tools.

                      (Sorry for spaming, I was to slow and meantime Gerolf answered the question)

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #21

                        [quote author="Jonathan" date="1292788447"]Perhaps the biggest hole in the Qt environment is the lack of integrated analysis tools, eg for memory leaks, performance analysis. The only option AFAIK is Valgrind.[/quote]

                        Analysis tools are highly platform dependent, so it would be hard to provide this in a platform independent manner and quality like the Qt libs. I personally am convinced, that it is also out of scope for a toolkit.

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        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