[Qt-interest] QHeaderView: built-in RMB menu to show/hide columns?
Robert Hairgrove
evorgriahr at hispeed.ch
Fri Feb 11 17:50:09 CET 2011
On Fri, 2011-02-11 at 12:16 +0100, Daniel Franke wrote:
> Hi all.
>
> Some applications that show data in a table view allow users to select
> the columns they want to see from a menu activated by right-clicking
> on the header view of the respective table. Examples are the message
> list of kmail and detailed display of dolphin in KDE.
>
> I can't find anything about it in the documentation of QTableView or
> QHeaderView - is there a simple standard way of implementing this
> feature? Google wasn't very helpful :(
QHeaderView objects emit signals such as "sectionClicked", but they
don't pass anything but the logical index as an argument. However,
quoting from the docs: "Use the QApplication::mouseButtons() function to
get the state of the mouse buttons."
In order to use these, you will probably have to subclass QHeaderView
and pass your object's pointer to setHeaderView() of the table view.
That way, you can connect the appropriate signals and slots in your own
code.
Alternatively, you could reimplement the protected mousePressEvent() in
your header view subclass. That might actually be the easiest way to go.
More information about the Qt-interest-old
mailing list