[PyKDE] context menu in QHeader

Andrew Dalke adalke at mindspring.com
Thu Apr 18 08:42:34 BST 2002


Boudewijn Rempt
> Yes, I see. You can't subclass QHeader and put your own subclass in
QTable.

I looked in the back mailing lists at trolltech.com and found that there's
about a request every month or two for this feature.

> However, I think (not tested, though), that you can subclass QTable, and
> have QTable catch the mouse events; simple artithmetic will then determine
> whether the user clicked in the header. There may well be better ways of
> doing it, but that's what I would try.

The subclassed QTable with an event filter on the QHeader worked just
fine.

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.

I'm still trying to figure this one out.  It looks like the Qt
widgets for the most part don't have mouseover feedback.  For example,
most of the widgets in designer don't have this, other than some of
the icon buttons, and neither do most of the elements in KSpread.

Looking around some more, I see there's a "QPalette" which defines
color and text styles for different widget states.  It only defines
it for keyboard focus states, and not for mouse position states.

Is it true then that the Qt library doesn't handle mouseover
highlighting as a standard part of their widget set?  Does anyone
else?

I note that IE and indeed most of the other MS apps I just tested
also don't support mouseover highlighting so this isn't a show
stopper, but I thought that context feedback like this was a good
idea.  Or is it done better with a mouse change? (which I find annoying)

Why oh why did I ever think about leaving back-end library
development?  APIs are so much easier.  :)

Boudewijn:
> Well, [event filters] are dealt with, passim, in chapter 15.  ...
> They were especially useful when you wanted a QMultiLineEdit where
> tab insert \t, instead hopping to the next widget.

Right, I think I recall that example now.

> This might actually be the solution for your problem (untested code
alert!):
  ..
> self.emit(PYSIGNAL("contextMenuRequested"), (ev,))

That should work - I'll give it a go.

I'm also using the event fiters to catch paint events in the QHeader,
as a way to experiment with providing that mouseover highlighting.
The problem is there doesn't seem to be a way to reuse the existing
drawing style, so I'll end up writing my own graphics.  In this case
they are simple enough, but still, I don't want to draw buttons.

> Good luck!

Thanks!

                    Andrew
                    dalke at dalkescientific.com






More information about the PyQt mailing list