what I want to do is to change the text of a QLable, everytime I hover with the mouse over the horizontalHeaders of my QTableWidget. How can I do that? Everytime I'm over a new header I need a signal and the index of the header. Hope someone of you has an idea. There must be a function, because if you hover over the headers, the background of the header changes.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Install an event filter that on the horizontalHeader() by using QObject.installEventFilter():
With
self.filter
in place, you'll be notified of the necessary events and can respond accordingly.UPDATE: it looks like HoverEvent isn't quite what we need. In order to get hover events, you need to setAttribute needs to be called with
Qt::WA_Hover
. From the documentation on this attribute:So yes, it generates events only when you enter or leave the widget.
Since the same header is used for all rows or all columns, we'll actually want to know about where the mouse is within the widget. Here's some new code which should handle mouse moves:
As you can see above, the main concept still applies. We either need an event filter so that we can watch for events or we need to subclass
QHeaderView
so that it will provide us with the necessary information.