Results 1 to 4 of 4

Thread: Selection problem in QTreeView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Selection problem in QTreeView

    I have a strange problem with every singe QTreeView in my program. When the program starts, I can select items in the tree views without a problem. However, that changes once I click on an item in the treeview and drag the mouse while holding the mouse button pressed (so that the selection changes to the item that the mouse cursor is currently over every time you drag the mouse cursor over an entry). After doing this, then it is no longer possible to select items by clicking on them. It is only possible to select items by pressing the mouse button and dragging the cursor to the item you want selected.

    Here is the constructor code from one of the QTreeViews :

    Qt Code:
    1. ArticleList::ArticleList()
    2. {
    3. setRootIsDecorated( false );
    4. setEditTriggers(QAbstractItemView::NoEditTriggers);
    5. model = new ArticleModel( QStringList(), this );
    6. setModel( model );
    7. setSelectionMode( QAbstractItemView::SingleSelection );
    8. ///Setup right click menu
    9. downloadArticle = new QAction( tr( "Download article" ), this );
    10. connect( downloadArticle, SIGNAL( triggered() ), this, SLOT( downloadArticleSlot() ) );
    11. menu = new QMenu();
    12. menu->addAction( downloadArticle );
    13. }
    To copy to clipboard, switch view to plain text mode 

    What could be causing this?

  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: Selection problem in QTreeView

    Are you overriding any events?
    J-P Nurmi

  3. #3
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Selection problem in QTreeView

    Yes.

    Qt Code:
    1. void ArticleList::mouseReleaseEvent( QMouseEvent *e )
    2. {
    3. e->accept();
    4. if( e->button() == Qt::RightButton ){
    5. menu->popup( e->globalPos() );
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    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: Selection problem in QTreeView

    Ok, that's the problem. You are preventing the QTreeView from handling mouse events properly. It will basically miss all mouse release events. Better use contextMenuEvent() for implementing context menus.

    Qt Code:
    1. void ArticleList::mouseReleaseEvent( QMouseEvent *e ){
    2. QTreeView::mouseReleaseEvent(e); // let QTreeView handle the event!
    3. // e->accept();
    4. // if( e->button() == Qt::RightButton ){
    5. // menu->popup( e->globalPos() );
    6. // }
    7. }
    8.  
    9. void ArticleList::contextMenuEvent(QContextMenuEvent *e){
    10. menu->popup( e->globalPos() );
    11. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    Valheru (7th October 2006)

Similar Threads

  1. QTreeView problem scrolling to end.
    By seneca in forum Qt Programming
    Replies: 7
    Last Post: 22nd December 2015, 12:08
  2. [SOLVED] QTreeView drawing selection with icons
    By Timewarp in forum Qt Programming
    Replies: 7
    Last Post: 7th February 2013, 07:52
  3. QTreeView repaint
    By graeme in forum Qt Programming
    Replies: 17
    Last Post: 13th March 2012, 13:27
  4. CheckBox and selection in QTableView
    By Mike Krus in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2006, 20:31
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.