0
votes

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

1 Answers

0
votes

In my application I have a controller class that handles a lot of application logic connected to various signals the tree view emits. This class is not suppost to render any visualization. Hence, it would be the most reasonable choice to derive from QObject. After a while I noticed, that it was in fact derived from QWidget. Being a QWidget I am guessing it tries to render some sort of visual representation, which the overlays the tree view. That's why I don't get any mouse events in some parts of the header.

After changing the base class of my controller to QObject, everything works fine again.