munna
13th July 2006, 14:54
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.
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())));
}
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.
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.
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())));
}
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.