Results 1 to 4 of 4

Thread: Collapse/Expand button in QTreeViewWidget

  1. #1
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    3
    Qt products
    Qt4

    Question Collapse/Expand button in QTreeViewWidget

    Hello,
    I want to write my own selection handling for my QTreeWidget. Unfortunatly the mechanism QT currently provides to do that doesn´t fit my needs. Thats why I created a class inheriting from QTreeWidget. In this class I deactivate (block!) all signals. The capture the for me necessary mouse events by overwriting mousePressEvent(QMouseEvent *event). It´s also possible to get an treeWidgetItem by using the coordinates. So far so good! But now I´m using a hierachical tree containing the collapse/expand button.

    My question: How can I found out when the user clicked this button???

    QTreeWidgetItem* l_TreeWidgetItem = itemAt(mapFromGlobal(QCursor:os())) and QModelIndex l_ModelIndex = indexAt(mapFromGlobal(QCursor:os())) show me what Item/ModelIndex was clicked but this didn´t help me. Any hints I could check out!?!?!

    Best regards - Skorpien126

  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: Collapse/Expand button in QTreeViewWidget

    Quote Originally Posted by Skorpien126 View Post
    In this class I deactivate (block!) all signals.
    Bad idea. I'd compare it to trying to stop a running car by pouring out all fuel from the fuel tank instead of just using breaks.

    Disabling signals effectively disables all functionality of QTreeWidget. What you should do instead (if you really need custom selection handling) is to reimplement the methods responsible for doing the selection or simply handling input events and manipulating the selection model yourself.
    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
    Jun 2010
    Posts
    10
    Thanks
    3
    Qt products
    Qt4

    Default Re: Collapse/Expand button in QTreeViewWidget

    Yeahhh.... you are right regarding this. But this is the only way to catch the events I need. I tried to use an event filter on my inheriting class to catch the mouseClick events. But seems that they are transmitted to the QTreeWidget - object. Something like this doesn´t work. Is there a reason for that??? (edit when I set the eventFilter on the viewPort() I can catch the signals but then the collapsing/expanding doesn´t work anymore)

    bool myTreeWidget::eventFilter(QObject *obj, QEvent *event)
    {
    // handle depending on eventType
    switch (event->type())
    {
    case QEvent::MouseButtonPress:
    // handle event for ourself
    return true;
    break;
    ...
    }
    }


    Handling the input events is basicly possible and also working. But unfortunately it´s to slow for our purpose!!! We need to handle about 5000 entries in out tree using a "intelligent" selection.


    By the way - is there flow chart showing in which order single signals are emitted when I take action (for example click on an item)???

    Thx for the input...
    Last edited by Skorpien126; 10th June 2010 at 08:23.

  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: Collapse/Expand button in QTreeViewWidget

    Quote Originally Posted by Skorpien126 View Post
    Yeahhh.... you are right regarding this. But this is the only way to catch the events I need.
    No. Events and signals don't interfere each other.

    If you are subclassing then using event filter on yourself doesn't make sense as you can reimplement required event handlers directly.
    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. QTreeWidget Expand/Collapse Button Size
    By Slewman in forum Qt Programming
    Replies: 3
    Last Post: 28th July 2010, 11:07
  2. QTabbar style ::scroller to expand the tab scoll button space.
    By AmolShinde_8 in forum Qt Programming
    Replies: 0
    Last Post: 22nd February 2010, 14:40
  3. QDockWidget Close instead of Collapse
    By GimpMaster in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2010, 23:01
  4. preserve collapse/expand of a QTreeView
    By yazwas in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2009, 09:49
  5. QTextEdit is possible collapse text?
    By angel75 in forum Qt Programming
    Replies: 2
    Last Post: 4th July 2006, 13:09

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.