Results 1 to 5 of 5

Thread: moving QListViewItems

  1. #1
    Join Date
    Feb 2006
    Posts
    91
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default moving QListViewItems

    QListViewItem *item =this->firstChild();
    while( item )
    {
    if(((myItem *)item)->isBoolFunction())
    {
    item->moveItem(this->firstChild());
    this->firstChild()->moveItem(item);

    }
    item =item->nextSibling();
    }
    I want to move one or more items to the top in a QListView.
    myItem is my class which inherits QListViewItem. Everything compiles fine ..however when the GUI is shown the application completely hangs and I have to literally kill the process...
    is this some kind of bug. I am using qt 3.1.1 on redhat. Any other way to do this nicely ?
    Humans make mistake because there is really NO patch for HUMAN STUPIDITY

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: moving QListViewItems

    But what exactly? You have only shown a snippet (not complete one) of a code that does something.

  3. #3
    Join Date
    Feb 2006
    Location
    Raleigh, NC
    Posts
    16
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: moving QListViewItems

    It sounds like you are never exiting your loop. I would put a break in there to make sure your exit condition is met.

  4. #4
    Join Date
    Feb 2006
    Posts
    91
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: moving QListViewItems

    actually the full code is too long and the two classes are in separate files so I was trying to just explain the scenario..
    here is the myItem class with the bool function ..
    class myItem : public QListViewItem
    {
    myItem(QListViewItem *parent,QString label);
    bool myBoolFunction();

    };
    bool myItem::myBoolFunction()
    {

    if(Flag)
    return true;
    else
    return false;
    }
    now all I want to do is for each listviewitem in the parentcheck whether the flag is set and is so move the item to the top to make the first child of the parent..
    in doing so I would have to iterate through all the childs of the parent and check the flag of each child through myBoolFunction()...

    also
    class myGroup : public QListViewItem
    {
    myGroup(QListView *parent,QString Label);
    void adjustGroups();

    }


    void adjustGroups()
    {
    QListViewItem *item =this->firstChild();
    while( item )
    {
    if(((myItem *)item)->isBoolFunction())
    {
    item->moveItem(this->firstChild());//works fine if i remove this
    this->firstChild()->moveItem(item);//works fine if i remove this
    count++;
    }
    item =item->nextSibling();
    }


    }
    the class that adjustGroup() is in is also a QListViewItem however it has several childs..and works fine if I remove the two lines...
    my guess is I am moving the item and then agian doing a item->nextSibling().... can we do this in some other way to move one or more items to the top of the list...

    where would I use this ??
    well in a messenger client when someone comes online then he/she is shifted to the top of its group... like in msn messenger... I am trying to do a similar thing
    Humans make mistake because there is really NO patch for HUMAN STUPIDITY

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: moving QListViewItems

    You might do it this way (it's just a concept):

    Qt Code:
    1. QPtrList<QListViewItem> _items;
    2. myItem *item = dynamic_cast<myItem>(this->firstChild());
    3. while(item){
    4. if(item->myBoolFunction()) _items.push_back(item);
    5. item = dynamic_cast<myItem>(item->nextSibling());
    6. }
    7. for(QPtrList<QListViewItem>::iterator it = _items.begin(); it!=_items.end();++it){
    8. takeItem(*it);
    9. insertItem(*it); // or some other method like moveItem()
    10. }
    To copy to clipboard, switch view to plain text mode 

    The first iteration looks for all items to move upwards, the second does the move.

Similar Threads

  1. QGraphicsView and fast moving objects
    By deMarco in forum Qt Programming
    Replies: 4
    Last Post: 26th February 2009, 11:07
  2. Moving a QMdiSubWindow
    By philwinder in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2008, 10:12
  3. Moving items between two views.
    By YuriyRusinov in forum Qt Programming
    Replies: 11
    Last Post: 2nd April 2007, 13:53
  4. why pushbutton moving??
    By Shuchi Agrawal in forum Qt Tools
    Replies: 7
    Last Post: 19th January 2007, 17:17
  5. Tooltips for QListViewItems (QT3)?
    By gadnio in forum Newbie
    Replies: 3
    Last Post: 13th March 2006, 17:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.