Results 1 to 4 of 4

Thread: QTreeWidget click

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QTreeWidget click

    Hi,
    I'm having a problem with a QTreeWidget.
    I've created a class derived from QTreeWidget and I've reimplemented "mouseReleaseEvent" as:
    Qt Code:
    1. void myTree::mouseReleaseEvent(QMouseEvent* event)
    2. {
    3. QTreeWidgetItem* pqItem = itemAt(event->pos());
    4. emit (emitItemClicked(pqItem));
    5. }
    To copy to clipboard, switch view to plain text mode 

    This let me know if the user has clicked into blank space(not an item).

    Then, the QWidgetTree automatically selects the clicked item. This works when I was using Qt 4.1.0, but now that I've updated to Qt 4.3.0 this don't work. The item is emmited, but the QTreeWidget sometimes select the item and sometimes don't(there are items to expand with "plus" also).

    Maybe have I to force the QTreeWidget to select the item? And, how to know if the user have clicked the "plus" or not?

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget click

    Hi,

    Well, seems to work:
    Qt Code:
    1. void myTree::mouseReleaseEvent(QMouseEvent* event)
    2. {
    3. QTreeWidgetItem* pqItem = itemAt(event->pos());
    4. this->setCurrentItem(pqItem);
    5. emit (emitItemClicked(pqItem));
    6. }
    To copy to clipboard, switch view to plain text mode 

    Thanks,
    Òscar Llarch i Galán

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget click

    Hi,

    mmm, it seems to work when it wants.
    Òscar Llarch i Galán

  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: QTreeWidget click

    With your code, the base class implementation receives only mouse press and mouse move events, but no mouse release events at all. No wonder if selection (handled by the base classes) is somehow broken..

    You should call the base class implementation so that it doesn't get out of sync:
    Qt Code:
    1. void myTree::mouseReleaseEvent(QMouseEvent* event)
    2. {
    3. QTreeWidget::mouseReleaseEvent(event);
    4. ...
    5. }
    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:

    ^NyAw^ (24th October 2007)

Similar Threads

  1. Double Click Capturing
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2011, 14:12
  2. QTreeWidget right click?
    By jbpvr in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2007, 20:03
  3. QGraphicsScene Click / Double Click
    By philentropist in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 04:32
  4. QTreeWidget double click signal
    By Pinco Pallino in forum Newbie
    Replies: 2
    Last Post: 18th November 2006, 16:37
  5. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32

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.