Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QHeaderView mouse tracking fails
QtWS25 Last Chance

QHeaderView mouse tracking fails

Scheduled Pinned Locked Moved Unsolved General and Desktop
qheaderviewqmouseevent
4 Posts 2 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vagabond
    wrote on 19 Jan 2016, 20:02 last edited by
    #1

    I need to connect some simple filter functionality, to a mouse click on a QTreeView header item. Simple enough, I implemented a slot function that connects to:

    QTreeView::header()->sectionClicked(int)
    

    After setting

    QTreeView::header()->setSectionsClickable(true)
    

    ,sectionClicked is emitted any time I click on a header that is highlighted by the default hover effect that any clickable header will produce.

    The issue is, hovering over some areas in clickable headers will not be recognized. Hence, in these parts there is no highlight and I will not get any sectionClicked triggers. I traced it back further and derived my own class from QHeaderView and put some output into mouseMoveEvent.

    class MyHeaderView : public QHeaderView
    {
        Q_OBJECT
    public:
        MyHeaderView(QWidget* parent = 0)
            : QHeaderView(Qt::Horizontal, parent)
        {
            setMouseTracking(true);
        }
    protected:
        virtual void mouseMoveEvent(QMouseEvent* event)
        {
            qDebug() << event->pos();
        }
    };
    

    While leaving all QTreeView settings as they were, I set an instance of this class to be the header via

    QTreeView::setHeader(QHeaderView*)
    

    I could see, that in all areas were the hover effect failed, I did not get the debug output you can see in the overridden mouseMoveEvent.

    As a result I am assuming, that the mouse tracking is not working correctly.

    The overall application I am working on is quiet big, so I set up a stand alone example, for all of this. To my surprise, everything works as expected. I am clueless, how I should proceed with this. Can anyone think of reasons for the mouse tracking to fail in some parts of a widget? Could it be a frame rate issue tied to lack of performance? Are there settings on widgets that affect the overall mouse tracked area? Can parent widgets affect mouse tracking?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 19 Jan 2016, 21:08 last edited by
      #2

      Hi and welcome to devnet,

      Do you have other subclass of QHeaderView that are used in your application ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      V 1 Reply Last reply 21 Jan 2016, 17:42
      0
      • S SGaist
        19 Jan 2016, 21:08

        Hi and welcome to devnet,

        Do you have other subclass of QHeaderView that are used in your application ?

        V Offline
        V Offline
        Vagabond
        wrote on 21 Jan 2016, 17:42 last edited by
        #3

        @SGaist Sorry I am only replying now. I thought I'd get an email if there was a reply to my question. Maybe there was and it just landed in the spam folder. I have been able to solve it.

        I have a CategoryWidget in my application, which contains a CategoryTreeView and a CategoryController instance. The CategoryTreeView is derived from QTreeView. CategoryController connects to a bunch of signals emitted from the tree view and handles application logic connected to these. It should not have any visual representation. Hence, the best choice for a base class would be QObject. Shamefully, I have after a while noticed that I had it set up as a QWidget.
        Since there is should not be a visualization for the controller, I obviously did not bother adding it to a layout in the CategoryWidget. As a result, it overlayed the tree view with an invisible widget area, which disallowed MouseEvents on the QTreeView underneath it.

        After changing the CategoryControllers BC to QObject everything works as expected.

        I guess this bug was a pretty good general lesson, to be more careful with BC definitions.

        Thanks!

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 21 Jan 2016, 21:44 last edited by
          #4

          You're welcome !

          You can also check in your profile settings whether the email notification is active.

          Since you have it working now, please mark the thread as solved using the "Topic Tool" button so that other forum users may know a solution has been found :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          2/4

          19 Jan 2016, 21:08

          • Login

          • Login or register to search.
          2 out of 4
          • First post
            2/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved