Results 1 to 6 of 6

Thread: Qt::ItemIsSelectable in a model/view structure

  1. #1
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Qt::ItemIsSelectable in a model/view structure

    I am trying to do an iTunes like sidebar with different sections.

    In the flags function from my QAbstractItemModel derived class I make sure not to return Qt::ItemIsSelectable for the items I like to use as titel for a section.
    At the execution, the different titels are not selectable if I try to click them which is good, but going up and down with the keyboard will make me go through these titels (they do not appear as selected, but I loose the selection on the previously selected item)

    What I would like to have is like in iTunes; if I have the selection on "iTunes Store" and pres the up key I will arrive immediatelly to the "Ringtone" element without stoping at the "Store" titel.

    If someone has an idea...

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt::ItemIsSelectable in a model/view structure

    I guess you could reimplement virtual method QAbstractItemView::moveCursor() to skip over them.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    schall_l (31st January 2008)

  4. #3
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Qt::ItemIsSelectable in a model/view structure

    Thank you very much, you're a genius.

  5. #4
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Qt::ItemIsSelectable in a model/view structure

    I would like to come back to my initial post:

    If I do have the selection on an item and then click on an item that can not be selected (means when the function flags from my QAbstractItemModel derived class does not return Qt::ItemIsSelectable) I do observe the following: the newly clicked item will not receive the selection which is what I want, but the previously selected one will loose it selection which is not what I want.

    What can I do to avoid the latest selected item to loose it selection when I do click (or double click) on an item that is not selectable ?

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt::ItemIsSelectable in a model/view structure

    I'd try with reimplementing QItemSelectionModel::select().
    J-P Nurmi

  7. #6
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Qt::ItemIsSelectable in a model/view structure

    Thank you,

    I've tested this by implementing a selection model class deriving from QItemSelectionModel and saw the following behavior

    -1- Clicking on a Qt::ItemIsSelectable item /b/ when beeing on a Qt::ItemIsSelectable item /a/ will call:
    select(const QItemSelection ... with command = 35 with selection containing the destinated selected item /b/
    select(const QModelIndex ... for the destinated selected item /b/ with command = 0
    select(const QItemSelection ... with command = 0 with selection containing the destinated selected item /b/


    -2- Clicking on a non Qt::ItemIsSelectable /b/ item when beeing on a Qt::ItemIsSelectable item /a/ will call:
    select(const QItemSelection ... with command = 35 with selection containing no item


    -3- Clicking on a Qt::ItemIsSelectable item /b/ when beeing on a non Qt::ItemIsSelectable /a/ item will call:
    select(const QItemSelection ... with command = 35 with selection containing the destinated selected item /b/
    select(const QModelIndex ... for the destinated selected item /b/ with command = 0
    select(const QItemSelection ... with command = 0 with selection containing the destinated selected item /b/


    -4- Clicking a non Qt::ItemIsSelectable item when beeing on a non Qt::ItemIsSelectable item will call:
    select(const QItemSelection ... is called with command = 35 with selection containing no item


    So it looked like the calls of the select functions are already the result of some kind of treatment resulting in the new selection.

    Finally I went to reimplement mousePressEvent and mouseReleaseEvent in order to catch the mouse events on a QModelIndex I do not want to be selectable:


    Qt Code:
    1. void
    2. SideBarTree::mousePressEvent(QMouseEvent *event)
    3. {
    4. QPoint pos = event->pos();
    5. QModelIndex index = indexAt(pos);
    6. if (index.row() == SideBar::Spacer1) return;
    7. if (index.row() == SideBar::Spacer2) return;
    8.  
    9. QTreeView::mousePressEvent(event);
    10. }
    11.  
    12. void
    13. SideBarTree::mouseReleaseEvent(QMouseEvent *event)
    14. {
    15. QPoint pos = event->pos();
    16. QModelIndex index = indexAt(pos);
    17. if (index.row() == SideBar::Spacer1) return;
    18. if (index.row() == SideBar::Spacer2) return;
    19.  
    20. QTreeView::mouseReleaseEvent(event);
    21. }
    To copy to clipboard, switch view to plain text mode 

    This seems to work.

Similar Threads

  1. Replies: 1
    Last Post: 1st March 2006, 11:43

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
  •  
Qt is a trademark of The Qt Company.