سؤال

Is there a way to allow for the right-click of the mouse? I want a menu to pop up when the right-button is clicked, Currently when the right button is clicked the program will exit. I have found information for keyboard shortcuts but i have not found any information for the mouse. I did look on the android developers site.

هل كانت مفيدة؟

المحلول

Depending on which environment you use it is different. But the scenario is the same. You need to create an event for that (extra you can calculate your mouse position to decide where to allow the right click). In Qt You can do something like following :

    void xxx::onRightClick()
{
  QPopupMenu* contextMenu = new QPopupMenu ( this );
  Q_CHECK_PTR ( contextMenu );

  contextMenu->insertItem ( "Copy" , this , SLOT (Copy()) );

  contextMenu->exec ( QCursor::pos() );
  delete contextMenu;
  contextMenu = 0;
}

Or you can just use an event filter. You can find the documentation for doing that in Qt here: Qt documentation for mouse events.

I hope this will help you.

Regards, Mikael

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top