Results 1 to 6 of 6

Thread: QTreeWidget and FocusPolicy issue

  1. #1
    Join Date
    Oct 2007
    Posts
    18
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default QTreeWidget and FocusPolicy issue

    Hello to all,

    i have a question. I have a QTreeWidget and i have some items which can be right-clicked and then i show a contextmenu. My problem is when i click in an empyt space in this widget the last clicked item isn't unselected - it still has focus. How can i fix this?
    I was thinking about ckecking for mouseclickevent and then to check if there is an item or not and if it is not unselect item but that doesn't seem a very good solution because i can have a lot of items in my TreeWidget.

    this are the settings for my QTreeWidget:

    m_TransfersTree->setSelectionBehavior( QAbstractItemView::SelectRows );
    m_TransfersTree->setSelectionMode( QAbstractItemView::SingleSelection );
    m_TransfersTree->setFocusPolicy(Qt::ClickFocus);

    Thank you all.

    regards,
    Borut

  2. #2
    Join Date
    Oct 2007
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget and FocusPolicy issue

    Hi there,
    I have never used with a TreeWidget, but with a TreeView... adopting my code to TreeWidget it should be something like:

    Qt Code:
    1. void myTreeWidget::contextMenuEvent( QContextMenuEvent *e )
    2. {
    3. if ( !e )
    4. {
    5. return;
    6. }
    7.  
    8. QTreeWidgetItem *pItem = itemAt( e->pos() );
    9. if ( !pItem )
    10. {
    11. clearSelection();
    12. return;
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    Does that help?

  3. #3
    Join Date
    Oct 2007
    Posts
    18
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTreeWidget and FocusPolicy issue

    thank yor for your answer but I don't think this is what i'm looking for or maybe i didn't explain well. I want for item to become unselected when i left-click in an empty space in this widget or when i select an item in another widget. Now when i left-click an empty space item is still selected (has focus) and if i select item in another TreeWidget item in previous widget still has focus. This is what i want to solve.

  4. #4
    Join Date
    Oct 2007
    Posts
    18
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTreeWidget and FocusPolicy issue

    Anyone? PLS

  5. #5
    Join Date
    Nov 2007
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: QTreeWidget and FocusPolicy issue

    Greetings.

    I think you are confusing the focus and the selection:
    "selected (has focus)" those two terms do not have the same meaning.

    That said, i would take your original approach, if the left mouse button has been clicked in a place where no valid item exists, inside your widget, simply clear selection.
    If you want to lose selection when you switch to another widget(i.e. lose focus), reimplement focusOutEvent aswell, and do a clearSelection there.

  6. #6
    Join Date
    Oct 2007
    Posts
    18
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTreeWidget and FocusPolicy issue

    Yes, maybe i am mixing those two things. But you understud what i was looking for I will try to do this although i thought that there should be an easier way to do this (i though that this is a default behaviour - when you click in an empty space or in another widget previously selected item that had focus now item looses focus).

    Thank you

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.