Results 1 to 10 of 10

Thread: How should I select QListWidgetItem by space-key

  1. #1
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default How should I select QListWidgetItem by space-key

    QAbstractItemView.ExtendedSelection allows just ctrl, shift combination.
    Is it possible only by using subclassing?

  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 should I select QListWidgetItem by space-key

    Use MultiSelection.
    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
    Nov 2010
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How should I select QListWidgetItem by space-key

    Thanks, wysota.
    But MultiSelection allows ONLY space-key.
    I want the selection of using 'shift + direction key' and 'space-key'.
    After all, subclassing is the solution, right?

  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 should I select QListWidgetItem by space-key

    Yes, you can always subclass.
    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:

    cookieki (8th November 2010)

  6. #5
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How should I select QListWidgetItem by space-key

    I tried to do subclassing of QAbstractItemViewPrivate::multiSelectionCommand.
    But that is not virtual
    Should I copy&paste all of the code of QAbstractItemViewPrivate to change only 'multiSelectionCommand'?

  7. #6
    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 should I select QListWidgetItem by space-key

    In my opinion you only need to reimplement keyPressEvent.
    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.


  8. #7
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How should I select QListWidgetItem by space-key

    Quote Originally Posted by wysota View Post
    In my opinion you only need to reimplement keyPressEvent.
    I have no idea.
    Qt Code:
    1. void QAbstractItemView::keyPressEvent(QKeyEvent *event)
    2. {
    3. ..
    4. QItemSelectionModel::SelectionFlags command = selectionCommand(newCurrent, event);
    5. ...
    6. }
    To copy to clipboard, switch view to plain text mode 

    Did you mean that change 'selectionCommand' to another?
    I need detail.

  9. #8
    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 should I select QListWidgetItem by space-key

    No, I meant to manipulate the item selection model of the view.

    A simplified version would be something close to this:
    Qt Code:
    1. void MyView::keyPressEvent(QKeyEvent *event){
    2. if(event->key()!=Qt::Key_Space) { QAbstractItemView::keyPressEvent(event); return; }
    3. selectionModel()->select(currentIndex(), QItemSelectionModel::SelectCurrent);
    4. }
    To copy to clipboard, switch view to plain text mode 
    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.


  10. #9
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How should I select QListWidgetItem by space-key

    Quote Originally Posted by wysota View Post
    No, I meant to manipulate the item selection model of the view.

    A simplified version would be something close to this:
    Qt Code:
    1. void MyView::keyPressEvent(QKeyEvent *event){
    2. if(event->key()!=Qt::Key_Space) { QAbstractItemView::keyPressEvent(event); return; }
    3. selectionModel()->select(currentIndex(), QItemSelectionModel::SelectCurrent);
    4. }
    To copy to clipboard, switch view to plain text mode 
    Thanks, wysota.
    It's not so simple.
    I want exactly 'Total Commander' style.
    To push direction key,with no shift key, is unselect all on ExtendedSelection mode.
    TC is not that. It's keep the selection state.

    I thought an idea. change between ExtendedSelection and MultiSelection.
    Basically set the MultiSelection and then change to the ExtendedSelection when shift and direction is pushed.
    But it's not works correctly. selection set is borken. I think maybe each mode have each selection set.

    The way you suggested has unselect-all-problem, too.
    Is there better way?

  11. #10
    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 should I select QListWidgetItem by space-key

    Quote Originally Posted by cookieki View Post
    The way you suggested has unselect-all-problem, too.
    Is there better way?
    It's just an idea you can build upon, not a ready solution. You can implement with it any selection algorithm 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.


Similar Threads

  1. Customize QListWidgetItem, how to?
    By martinn in forum Qt Programming
    Replies: 24
    Last Post: 12th December 2016, 11:47
  2. QTableView empty space or too little space.
    By davemar in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2009, 17:00
  3. Replies: 1
    Last Post: 26th July 2009, 16:08
  4. about QListWidgetItem
    By Pang in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2007, 10:14
  5. linking user space and kernel space programs with qmake
    By zielchri in forum Qt Programming
    Replies: 9
    Last Post: 9th March 2006, 00:11

Tags for this Thread

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.