[PyKDE] context menu in QHeader
Andrew Dalke
adalke at mindspring.com
Wed Apr 17 21:30:24 BST 2002
Boudewijn: (from private email)
> have you tried using the event functions of QWidget? You can catch
> any mouse event anywhere using them, and then use a QPopupMenu.
A-ha, that works.
[now list email]
> QHeader inherits QWidget, which has a method, mousePressEvent(QEvent ev).
> You can find out which kind of press occurred, and also the location
> of the press. From there, it's easy to instantiate and populate a
> QPopupMenu.
I tried that, but mousePressEvent is a virtual method of the QWidget,
which (if I understand correctly) means I would need to derive from
QHeader to get that call. I tried treating it as a signal, but PyQT
complained and wouldn't let me.
In a related question, I want the column headers to provide some
feedback during mouseover (eg, by having the background become a
lighter shade of grey). I tried setting the options that seemed
even vaguely relevant, but none worked.
It seems I should be able to implement my own paint method to do
that, but it again requires that I be able to tell the QTable to use
my derived QHeader and not the default one.
> Keep in mind that signals/slots are meant for communication between
objects.
> Events are meant for the handling of user input -- key presses, mouse
stuff,
> things like that.
I (think) I understand. Again, it's only been a couple of days. But
since there was a 'contextMenuRequested' event for the cells I figured
there would also be a contextMenuRequested signal for the headers, and
it appears that there isn't.
> Have you seen
>
http://www.opendocspublishing.com/pyqt/index.lxp?lxpwrap=x2629%2ehtm#AEN2679
...
> where I discuss events?
Yes, I have. Indeed, thank you for writing it because that publication
is one of the reasons I'm looking more into Qt, since I wouldn't have
wanted to figure this all on my own.
I think I follow how events work, it's just that I don't know what to
do when there isn't the event I'm looking for. For example, I don't
recall anything in your book on event filters, nor any example close
enough to what I'm working on for me to tweak.
> As for the rest: QGrid isn't a widget, but a layout manager, actually. For
> your purpose, QTable should work best.
My mistake. I just started with Qt a couple days ago and I'm still
lost in the maze of different names. I meant to say QTable.
Andrew
dalke at dalkescientific.com
More information about the PyQt
mailing list