C++ (Qt)class MyMenu : public QMenu {protected: void mouseReleaseEvent(QMouseEvent * e) { if (e->button() != Qt::LeftButton) return; QMenu::mouseReleaseEvent(e); }};
C++ (Qt) const QModelIndex & index = ui->view->currentIndex(); if (index.isValid()) { MyMenu menu;// QMenu menu; menu.addAction(ui->actionAddStudent); menu.addAction(ui->actionRemoveStudent); menu.exec(QCursor::pos()); }
C++ (Qt)void ProxyList::mousePressEvent(QMouseEvent *event){ if(event->button() == Qt::MidButton) { return; } if(event->button() == Qt::RightButton) { setCurrentIndex( indexAt( event->pos() ) ); return; } QListView::mousePressEvent(event);}
C++ (Qt)void ProxyPaneWidget::showCustomMenu( QPoint const & pos ){ bool selectionEmpty = m_proxyList->selectionModel()->selection().empty(); QAction * deleteAction = new QAction( this ); deleteAction->setText( tr( "Delite" ) ); deleteAction->setShortcut( QKeySequence( QKeySequence::Delete ) ); deleteAction->setShortcutContext( Qt::WidgetWithChildrenShortcut ); connect( deleteAction, SIGNAL( triggered() ), this, SLOT( deleteSelectedItem() ) ); QMenu * proxyMenu = new QMenu( this ); proxyMenu->addAction( tr( "Ascending" ), this, SLOT(sortAscendingOrder()) ); proxyMenu->addAction( tr( "Descending" ), this, SLOT(sortDescendingOrder()) ); proxyMenu->addAction( tr( "Reset" ), this, SLOT(resetProxy()) ); if ( !selectionEmpty ){ proxyMenu->addSeparator(); proxyMenu->addAction( m_deleteAction ); } proxyMenu->exec( m_proxyList->mapToGlobal( pos ) );}
C++ (Qt) explicit ProxyPaneWidget( QWidget * parent = 0 ) : QWidget( parent ) { m_deleteAction = new QAction( this ); m_deleteAction->setText( tr( "Delite" ) ); m_deleteAction->setShortcut( QKeySequence::Delete ) ; m_deleteAction->setShortcutContext( Qt::WidgetWithChildrenShortcut ); connect( m_deleteAction, SIGNAL( triggered() ), this, SLOT( deleteSelectedItem() ) ); addAction( m_deleteAction ); }
C++ (Qt)void ProxyPaneWidget::showCustomMenu(QPoint const & pos){ bool selectionEmpty = m_proxyList->selectionModel()->selection().empty(); QMenu * m_proxyMenu = new QMenu( this ); m_proxyMenu->addAction( tr( "Ascending" ), this, SLOT( sortAscendingOrder()) ); m_proxyMenu->addAction( tr( "Descending" ), this, SLOT( sortDescendingOrder()) ); m_proxyMenu->addAction( tr( "Reset" ), this, SLOT( resetProxy()) ); if ( !selectionEmpty ) { m_proxyMenu->addSeparator(); m_proxyMenu->addAction( m_deleteAction ); } m_proxyMenu->exec( m_proxyList->mapToGlobal( pos ) );}
C++ (Qt) QAction * deleteAction = new QAction( this );... QMenu * proxyMenu = new QMenu( this );
C++ (Qt) QMenu proxyMenu( this ); QAction * deleteAction = new QAction( &proxyMenu );
C++ (Qt) QAction * deleteAction = new QAction( this ); QMenu * proxyMenu = new QMenu( this );... delete proxyMenu; delete deleteAction;
C++ (Qt)void ProxyPaneWidget::showCustomMenu(QPoint const & pos){ bool selectionEmpty = m_proxyList->selectionModel()->selection().empty(); QMenu m_proxyMenu( this ); m_proxyMenu.addAction( tr( "Ascending" ), &m_proxyMenu, SLOT(sortAscendingOrder()) ); m_proxyMenu.addAction( tr( "Descending" ), &m_proxyMenu, SLOT(sortDescendingOrder()) ); m_proxyMenu.addAction( tr( "Reset" ), &m_proxyMenu, SLOT(resetProxy()) ); if ( !selectionEmpty ) { m_proxyMenu.addSeparator(); m_proxyMenu.addAction( m_deleteAction ); } m_proxyMenu.exec( m_proxyList->mapToGlobal( pos ) );}
C++ (Qt)void ProxyPaneWidget::showCustomMenu(QPoint const & pos){ bool selectionEmpty = m_proxyList->selectionModel()->selection().empty(); QMenu m_proxyMenu( this ); m_proxyMenu.addAction( tr( "Ascending" ), this, SLOT(sortAscendingOrder()) ); m_proxyMenu.addAction( tr( "Descending" ), this, SLOT(sortDescendingOrder()) ); m_proxyMenu.addAction( tr( "Reset" ), this, SLOT(resetProxy()) ); if ( !selectionEmpty ) { m_proxyMenu.addSeparator(); m_proxyMenu.addAction( m_deleteAction ); } m_proxyMenu.exec( m_proxyList->mapToGlobal( pos ) );}