Sarol
16th June 2011, 19:17
Good Day Everyone,
Before getting to my question here is a brief overview of what I'm working on:
I have a QMainWindow Form that has a few push buttons and a QTableWidget. I have created a customContextMenu for when a user right clicks on the QTableWidget.
For the most part everything works as intended, but here are my questions/issues.
1) Once I right on the QTableWidget the menu appears where the mouse cursor is, but will not disappear until another click ( left/right ) is detected. Is there a way to hide the menu once the cursor is no longer on top of it, or moves a certain distance away? ( I thought I saw a post on this once before, but am having trouble locating it to see if it helps with my issue )
2) Is there a way to prevent the context menu from displaying on empty rows? My general thought is to do something with the cursor position and check where it is in relation to the table, and then see if there is a valid row at that particular point. However, I am unsure of how to really do this.
Here is the method I used for creating my menu
void QTMainform::contextMenuRequested( const QPoint& )
{
//QPoint globalPos = this->mapToGlobal( pos ) ;
QMenu myMenu ;
myMenu.addAction( "Start" , this , SLOT( start()) ) ;
myMenu.addAction( "Stop" , this , SLOT( stop() ) ) ;
myMenu.addAction( "Help" , this , SLOT( help() ) ) ;
myMenu.exec( QCursor::pos() ) ;
}
Any help is appreciated.
Thanks
Before getting to my question here is a brief overview of what I'm working on:
I have a QMainWindow Form that has a few push buttons and a QTableWidget. I have created a customContextMenu for when a user right clicks on the QTableWidget.
For the most part everything works as intended, but here are my questions/issues.
1) Once I right on the QTableWidget the menu appears where the mouse cursor is, but will not disappear until another click ( left/right ) is detected. Is there a way to hide the menu once the cursor is no longer on top of it, or moves a certain distance away? ( I thought I saw a post on this once before, but am having trouble locating it to see if it helps with my issue )
2) Is there a way to prevent the context menu from displaying on empty rows? My general thought is to do something with the cursor position and check where it is in relation to the table, and then see if there is a valid row at that particular point. However, I am unsure of how to really do this.
Here is the method I used for creating my menu
void QTMainform::contextMenuRequested( const QPoint& )
{
//QPoint globalPos = this->mapToGlobal( pos ) ;
QMenu myMenu ;
myMenu.addAction( "Start" , this , SLOT( start()) ) ;
myMenu.addAction( "Stop" , this , SLOT( stop() ) ) ;
myMenu.addAction( "Help" , this , SLOT( help() ) ) ;
myMenu.exec( QCursor::pos() ) ;
}
Any help is appreciated.
Thanks