Implementation of right click for Vertical/Horizontal Headers in QTable
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.
Re: Implementation of right click for Vertical/Horizontal Headers in QTable
Apply an event filter on the QHeader object (you can access it using QTable::verticalHeader() and QTable::horizontalHeader() and process its mousePressEvent.
Re: Implementation of right click for Vertical/Horizontal Headers in QTable
Hi,
I tried installing event filter on horizontal header for QTable.
Something like this...
Code:
class MyTable : public QTable
{
public:
MyTable
(QWidget* parent,
const char* name
);
}
MyTable
::MyTable(QWidget* parent,
const char* name
):QTable
(parent,name
){
horizontalHeader ()->installEventFilter(this);
}
{
if (pTarget == horizontalHeader())
{
if (pEvent
->type
() == QEvent::MouseButtonRelease) {
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:
Re: Implementation of right click for Vertical/Horizontal Headers in QTable
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.
Re: Implementation of right click for Vertical/Horizontal Headers in QTable
Hi !
It worked!
Thanks :-)