View Full Version : Implementation of right click for Vertical/Horizontal Headers in QTable
sukanyarn
26th September 2006, 09:50
Greetings,
I am using Qt 3.3.2.
I am working with QTable.
I find that there is no right clicked signal for the verticalHeader and horizontalHeader for tables.
There is only left clicked signal for the headers.
Now, I would like to know if there is a way to implement right click feature for the vertical and horizontal headers for tables.
Thanks in advance.
wysota
26th September 2006, 09:55
Apply an event filter on the QHeader object (you can access it using QTable::verticalHeader() and QTable::horizontalHeader() and process its mousePressEvent.
sukanyarn
27th September 2006, 13:16
Hi,
I tried installing event filter on horizontal header for QTable.
Something like this...
class MyTable : public QTable
{
public:
MyTable(QWidget* parent, const char* name);
}
MyTable::MyTable(QWidget* parent, const char* name):QTable(parent,name)
{
horizontalHeader ()->installEventFilter(this);
}
bool MyTable::eventFilter(QObject *pTarget, QEvent *pEvent)
{
if (pTarget == horizontalHeader())
{
if (pEvent->type() == QEvent::MouseButtonRelease)
{
QMouseEvent *pMouseEvent = (QMouseEvent *)pEvent;
if (pMouseEvent->button() == Qt::RightButton)
{
qWarning(" vertical header right clicked!! ");
// do something
}
}
}
return QObject::eventFilter(pTarget, pEvent);
}
When i righclick on horizontal header of my table, it is getting caught!. But, my table is not displaying any information ( data in cells ) that it used to before installing event filter on
horizontal header :(
Some light please! :rolleyes:
wysota
27th September 2006, 14:11
Return false (or better yet QTable::eventFilter) from the filter when you process the event so that QHeader can do processing of its own.
And don't return QObject::eventFilter if you don't process the event yourself. You should return the base class implementation, QTable::eventFilter() in this case.
sukanyarn
27th September 2006, 14:34
Hi !
It worked!
Thanks :-)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.