context menu not displaying
I created a table inside a function and connect as below...
filesTable= new QTableWidget(this);
connect(filesTable,SIGNAL(customContextMenuRequest ed(QPoint)),this,SLOT(ProvideContextMenu(QPoint))) ;
but, it is not generating signal, i am unable too see any context menu over there...
Re: context menu not displaying
customContextMenuRequested() signal is only emitted with ContextMenuPolicy set to Qt::CustomContextMenu , so you
need to add this:
filesTable->setContextMenuPolicy(Qt::CustomContextMenu);
*and why did you leave a whitespace in "SIGNAL(customContextMenuRequest_ed(QPoint)
Re: context menu not displaying
Thank u so much Alex...
But problem is that context menu is not displaying where mouse pointer is...It is displaying somewhere else..
What changes i need to do?
my code as shown below...
Code:
void MainWindow
::ProvideContextMenu(const QPoint &pos
) {
cout<<"EVENT GENERATED..."<<cell.toStdString()<<endl;
pContextMenu->addAction(pAddAction);
pContextMenu->addAction(pSplitAction);
pContextMenu->exec(mapToGlobal(pos));
}
Re: context menu not displaying
Coordinate transformations might be tricky...Here is a code snippet i used long time ago...and the thing is that i'm not sure if i figured it out completely back then...cuz i had the same problem.
Code:
//..
// ...
void Widget
::customContextMenuRequested(const QPoint &point
) {
if( index.isValid() )
{
QPoint viewPortPosition
= view
->pos
();
int headerOffset = view->horizontalHeader()->sectionSize(0);
int adjustedHeight = viewPortPos.y() + headerOffset;
viewPortPos.setY(adjustedHeight);
// ...
menu.
exec( mapToGlobal
(QPoint( viewPortPos
+ point
) ) );
}
}
Even thought i've used QTableView , i'm sure it's gonna give you an idea...If you find that there is something wrong with my implementation (i'm sure there is:D) , i'd be glad to hear the right way to do it!^^
Re: context menu not displaying
Re: context menu not displaying
Quote:
Originally Posted by
AlexSudnik
*and why did you leave a whitespace in "SIGNAL(customContextMenuRequest_ed(QPoint)
The space is inserted by the forum to break up long "words" when the poster cannot be bothered to use [code][/code] tags around code.
Re: context menu not displaying
You still have it appearing in the wrong space ? If so...you just want to use QTableWidget's context menu , right ?
P.S : ChrisW67 - thanks^^ , i see now^^
Re: context menu not displaying
ya right now i'm using QTable widget but thinking to change it table view.....
Re: context menu not displaying
Re: context menu not displaying
Hmm , try this:
Code:
void Widget::ProvideContextMenu( const QPoint& position )
{
if( index.isValid( ) ) // not neccessary , if you're about to perform item-independent actions
{
menuAction.setText("Demonstrational Text");
menu.addAction(&menuAction);
menu.exec( mapToGlobal( position ) );
}
}
Since initial point coordinates are given in the widget's local space (i mean , not in QWidget * QAbstractScrollArea::viewport () coordinates ) , we have to display it in the same space , using mapToGlobal function.