Results 1 to 10 of 10

Thread: How to ignore current item change in QListWidget?

  1. #1
    Join Date
    Mar 2009
    Location
    Russia
    Posts
    6
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to ignore current item change in QListWidget?

    The question as well relates to other QAbstractItemView derivates.
    I want to check some condition if I go to new current item. If it fails - then nothing should happen, and current item should remain the same.

  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: How to ignore current item change in QListWidget?

    Very good. And?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Russia
    Posts
    6
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to ignore current item change in QListWidget?

    Quote Originally Posted by wysota View Post
    Very good. And?
    I don't know how to do this. I can call QListWidget::setCurrentItem(prev) in the QListWidget::currentItemChanged(QListWidgetItem * curr, QListWidgetItem * prev), but this will lead to a recursion of some kind. Is there any other way?

  4. #4
    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: How to ignore current item change in QListWidget?

    If you provide a stop condition, you will prevent recursing.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    GNU/Varan (13th May 2011)

  6. #5
    Join Date
    Mar 2009
    Location
    Russia
    Posts
    6
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to ignore current item change in QListWidget?

    Quote Originally Posted by wysota View Post
    If you provide a stop condition, you will prevent recursing.
    Ok. It's not rather elegant, though, if I have two nested levels of lists and the condition is on the ground level...

    Moreover, the top level is QTreeView...
    Last edited by GNU/Varan; 13th May 2011 at 14:14.

  7. #6
    Join Date
    Mar 2009
    Location
    Russia
    Posts
    6
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to ignore current item change in QListWidget?

    By the way - how to deal with selection? It's independent of current item so I run into situation when the current item is right whereas the selected item is wrong.

  8. #7
    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: How to ignore current item change in QListWidget?

    How do you want to "deal" with it? You have the selection model and you can manipulate it as you want.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #8
    Join Date
    Mar 2009
    Location
    Russia
    Posts
    6
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to ignore current item change in QListWidget?

    But in what function must I manipulate it? I do something like
    Qt Code:
    1. ui.subprograms->setCurrentItem(prev);
    2. ui.subprograms->selectionModel()->select(ui.subprograms->currentIndex(), QItemSelectionModel::SelectCurrent);
    To copy to clipboard, switch view to plain text mode 
    or even
    Qt Code:
    1. ui.subprograms->setCurrentItem(prev);
    2. prev->setSelected(true);
    To copy to clipboard, switch view to plain text mode 
    in my "currentItemChanged"-handler but this has no effect. Seems like selection automatically changes after the current item.
    Should I override
    Qt Code:
    1. void QAbstractItemView::selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected )
    To copy to clipboard, switch view to plain text mode 
    as well?

  10. #9
    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: How to ignore current item change in QListWidget?

    You should connect to QItemSelectionModel's selectionChanged() signal.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. The following user says thank you to wysota for this useful post:

    GNU/Varan (17th May 2011)

  12. #10
    Join Date
    Aug 2008
    Posts
    18
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to ignore current item change in QListWidget?

    I had the same problem as yours. It seems like QT is not capable of handling this situation. Since the actual change of the selection happens after the slot returns, and while in the slot, the prev item is still the "current" item, so setCurrentItem(prev) in the slot won't do anything new. In MFC, you can set a flag bit in the event to tell the system not to set the selection change so the old selection will still be valid after the event handler returns.
    Last edited by yren; 19th July 2011 at 19:50.

Similar Threads

  1. Replies: 0
    Last Post: 10th March 2011, 11:44
  2. get and set current item in QTableView
    By pospiech in forum Newbie
    Replies: 8
    Last Post: 25th May 2009, 13:25
  3. current item in treeview
    By kernel_panic in forum Qt Programming
    Replies: 2
    Last Post: 30th October 2007, 19:26
  4. get current item from QCompleter
    By evgenM in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 18:16
  5. Replies: 1
    Last Post: 19th April 2007, 22:23

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.