Results 1 to 5 of 5

Thread: QAbstractItemView selection behaviour issue

  1. #1
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QAbstractItemView selection behaviour issue

    Hello,
    I get a little bit confused with the way selection behaviour in MVC views should be handled. More more precisely there are 2 places where selection behaviour can be described:

    1) I put these lines in the constructor of my view:
    this->setSelectionBehavior(QAbstractItemView::SelectRow s);
    this->setSelectionMode(QAbstractItemView::ExtendedSelec tion);
    2) In response to some event I put these lines in a mouseReleaseEvent() function
    QItemSelectionModel::SelectionFlags flags(QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent);
    if (!this->ctrl_key)
    flags |= QItemSelectionModel::Clear;
    this->setSelection(r, flags);
    and of course in the setSelection() method, I put:
    this->selectionModel()->select(sel, flags);
    where sel is a QItemSelection.

    I would expect either 1) or 2) be enough for the extended selection behaviour to work, that is clicking on an item while handling the control key (in this case this->ctrl_key == 1) should select a new item while keeping the already selected ones selected. But even with both codes it does not work!
    So my questions are:
    - which mistake(s) in my code?
    - should I use 1) and/or 2) for the extended selection behaviour to work?
    Thanks in advance for your help.

    Caius

    PS: I use Qt4.1

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QAbstractItemView selection behaviour issue

    How do you determine that the control key is pressed?

  3. #3
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QAbstractItemView selection behaviour issue

    Quote Originally Posted by marcel View Post
    How do you determine that the control key is pressed?
    in a keyPressedEvent() slot, which makes this->ctrl_key = 1;

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QAbstractItemView selection behaviour issue

    I am afraid this is not correct. You must determine the modifier keys in the mouse event, with QMouseEvent::modifiers().

    regards

  5. #5
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QAbstractItemView selection behaviour issue

    Quote Originally Posted by marcel View Post
    I am afraid this is not correct. You must determine the modifier keys in the mouse event, with QMouseEvent::modifiers().

    regards
    Thanks for the tips, it is more elegant and easier to do like this BUT the problem was not here since my way of detecting ctrl key press prior to clicking on an item works too (I printed the value of ctrl_key to check it of coursee) so the clear flag is off and I would expect that the already selected items remain selected, which is not the result I obtain.
    Any help?

Similar Threads

  1. QTable Selection Issue
    By ToddAtWSU in forum Qt Programming
    Replies: 3
    Last Post: 6th February 2007, 13:37

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.