Results 1 to 14 of 14

Thread: setSelection() in custom view

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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: setSelection() in custom view

    Quote Originally Posted by krudio View Post
    I'm still confused as to what the selection rect is? Is that equivalent to the rectangle that appears when you click and drag to select a group of icons on a desktop, for example? If so, we are not supporting that kind of functionality in our custom view..
    Yes, it's mainly that. In addition to that, it is also used to make the "current item" selected while navigating with keyboard.
    J-P Nurmi

  2. #2
    Join Date
    Nov 2007
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setSelection() in custom view

    Quote Originally Posted by jpn View Post
    Yes, it's mainly that. In addition to that, it is also used to make the "current item" selected while navigating with keyboard.
    Ok, that makes sense. So which method then is responsible for selecting an item when a user clicks on it with the mouse? Is it visualRegionForSelection()?

  3. #3
    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: setSelection() in custom view

    Quote Originally Posted by krudio View Post
    Ok, that makes sense. So which method then is responsible for selecting an item when a user clicks on it with the mouse? Is it visualRegionForSelection()?
    QAbstractItemView::setSelection() is called from both, QAbstractItemView::mousePressEvent() and QAbstractItemView::mouseMoveEvent().
    J-P Nurmi

  4. #4
    Join Date
    Nov 2007
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setSelection() in custom view

    Quote Originally Posted by jpn View Post
    QAbstractItemView::setSelection() is called from both, QAbstractItemView::mousePressEvent() and QAbstractItemView::mouseMoveEvent().
    So should I override mousePressEvent() and mouseMoveEvent() in my custom view to support the selection of my custom items?

  5. #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: setSelection() in custom view

    No, setSelection() is fine. What's the problem with it?
    J-P Nurmi

  6. #6
    Join Date
    Nov 2007
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setSelection() in custom view

    Quote Originally Posted by jpn View Post
    No, setSelection() is fine. What's the problem with it?
    Well, I guess my problem is that I do not need to support selection with a rectangle or with the keyboard. I only want items to be selected when a user clicks on them with the mouse. Unfortunately, setSelection() only takes a QRect and a SelectionFlag as parameters. What is your recommendation in this case?

  7. #7
    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: setSelection() in custom view

    Quote Originally Posted by krudio View Post
    Well, I guess my problem is that I do not need to support selection with a rectangle or with the keyboard. I only want items to be selected when a user clicks on them with the mouse. Unfortunately, setSelection() only takes a QRect and a SelectionFlag as parameters. What is your recommendation in this case?
    Well, I'd implement the selection like the framework expects you to, with setSelection(). Notice that there are a few built-in properties to adjust the way selection works (namely selection behavior and mode). These properties are properly taken into consideration in various methods of QAbstractItemView which further call setSelection(). So I'd use setSelection() instead of reimplementing the selection from scratch to a certain event handler. You can later restrict the ways of selection if really required, for example with empty event handler reimplementation(s).
    J-P Nurmi

  8. #8
    Join Date
    Nov 2007
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setSelection() in custom view

    Quote Originally Posted by jpn View Post
    Well, I'd implement the selection like the framework expects you to, with setSelection(). Notice that there are a few built-in properties to adjust the way selection works (namely selection behavior and mode). These properties are properly taken into consideration in various methods of QAbstractItemView which further call setSelection(). So I'd use setSelection() instead of reimplementing the selection from scratch to a certain event handler. You can later restrict the ways of selection if really required, for example with empty event handler reimplementation(s).
    Ok, I have the selection behavior and mode flags set the way I want them, but I'm still confused on how to re-implement setSelection() for what I need it to do. Since the method is not passed a QPoint or QModelIndex, I have no way to tell which item the user clicked on. Do you see my dilemma here?

  9. #9
    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: setSelection() in custom view

    My guess is that "indexAt(rect.center())" is suitable for you.
    J-P Nurmi

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

    krudio (6th February 2008)

Similar Threads

  1. Model-view: Creating a custom view
    By taboom in forum Qt Programming
    Replies: 5
    Last Post: 17th August 2007, 20:36
  2. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50
  3. Custom widget in list view
    By fusoin23 in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2006, 14:09
  4. Replies: 1
    Last Post: 13th July 2006, 21:10
  5. Example HowTo create custom view
    By dexjam in forum Newbie
    Replies: 6
    Last Post: 12th July 2006, 11:06

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.