Hi,
How can I get the rect of a section of headerView so that I can make a menu appear in a section of a headerView.
I wrote the following code but it is not working.
{
setAlternatingRowColors(true);
verticalHeader()->hide();
tableHeader = new TableHeader(this);
setHorizontalHeader(tableHeader);
headerMenu
= new QMenu(tr
("Undefined"),tableHeader
);
connect(headerMenu,
SIGNAL(triggered
(QAction *)),
this,
SLOT(headerMenuTriggered
(QAction *)));
populateHeaderMenu();//Add the actions to the menu
}
//The following slot is not called itself
void DataTable
::headerClicked(const QModelIndex &index
) {
//I wonder if this is correct.
QRect rect
= visualRect
(index
);
headerMenu
->exec
(tableHeader
->mapToGlobal
(QPoint(rect.
x(),rect.
y())));
}
DataTable::DataTable(QWidget *parent) : QTableWidget(parent)
{
setAlternatingRowColors(true);
verticalHeader()->hide();
tableHeader = new TableHeader(this);
connect(tableHeader,SIGNAL(clicked(const QModelIndex &)),this,SLOT(headerClicked(const QModelIndex &)));
setHorizontalHeader(tableHeader);
headerMenu = new QMenu(tr("Undefined"),tableHeader);
connect(headerMenu,SIGNAL(triggered(QAction *)),this,SLOT(headerMenuTriggered(QAction *)));
populateHeaderMenu();//Add the actions to the menu
}
//The following slot is not called itself
void DataTable::headerClicked(const QModelIndex &index)
{
//I wonder if this is correct.
QRect rect = visualRect(index);
headerMenu->exec(tableHeader->mapToGlobal(QPoint(rect.x(),rect.y())));
}
To copy to clipboard, switch view to plain text mode
The same menu needs to appear for all the columns and therefore I used this way.
Is there a better way of doing it.
Can someone please help me with this?
Thanks a lot.
Bookmarks