当前位置: 首页>>代码示例>>C++>>正文


C++ QMenu::popup方法代码示例

本文整理汇总了C++中QMenu::popup方法的典型用法代码示例。如果您正苦于以下问题:C++ QMenu::popup方法的具体用法?C++ QMenu::popup怎么用?C++ QMenu::popup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QMenu的用法示例。


在下文中一共展示了QMenu::popup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: on_all_table_customContextMenuRequested

void MainWindow::on_all_table_customContextMenuRequested(const QPoint &pos)
{
    QModelIndex index = ui->all_table->indexAt(pos);
    if(!index.isValid())
        return;
    book_name = ui->all_table->selectedItems()[0]->text().toStdString();
    selected_row = ui->all_table->selectedItems()[0];
    QMenu* menu = new QMenu(this);
    QAction* action = 0;
    if(DB::db()->user()->get_library()->is_in_library(book_name))
    {
        cerr << "1" << endl;
        if(!DB::db()->user()->get_library()->is_in_starred(book_name))
        {
            action = new QAction("Like this", this);
            menu->addAction(action);
            connect(action,SIGNAL(triggered()),this,SLOT(like()));
        }

        vector<Shelf*> shelves = DB::db()->user()->get_library()->get_shelves();
        int count = 0;
        for(int i = 0; i < shelves.size(); i++)
        {
            if(shelves[i]->get_name() == "default")
                continue;
            if(shelves[i]->has_book(book_name))
                continue;
            count++;
        }
        if(count > 0)
        {
            action = new QAction("Add to Shelf", this);
            menu->addAction(action);
            connect(action,SIGNAL(triggered()),this,SLOT(add_to_shelf()));
        }
    }
    else
    {

        action = new QAction("Add To Library",this);
        menu->addAction(action);
        connect(action,SIGNAL(triggered()),this,SLOT(add_to_library()));
    }
    menu->popup(ui->all_table->viewport()->mapToGlobal(pos));
}
开发者ID:py4,项目名称:memphis,代码行数:45,代码来源:mainwindow.cpp

示例2: contextMenuEvent

//-----------------------------------------------------------------------------
void qtSqueezedLabel::contextMenuEvent(QContextMenuEvent* e)
{
  if (this->contextMenuPolicy() == Qt::DefaultContextMenu)
    {
    QMenu* menu = new QMenu(this);
    menu->setAttribute(Qt::WA_DeleteOnClose);

    QAction* action = menu->addAction("&Copy Full Text");
    action->setEnabled(!this->fullText().isEmpty());
    connect(action, SIGNAL(triggered()), this, SLOT(copy()));

    menu->popup(e->globalPos());
    e->accept();
    return;
    }

  QLabel::contextMenuEvent(e);
}
开发者ID:Kitware,项目名称:qtextensions,代码行数:19,代码来源:qtSqueezedLabel.cpp

示例3: showContextMenu

void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )
{
  QModelIndex idx = mBrowserView->indexAt( pt );
  QgsDataItem* item = mModel->dataItem( idx );
  if ( !item )
    return;

  QMenu* menu = new QMenu( this );

  if ( item->type() == QgsDataItem::Directory )
  {
    QSettings settings;
    QStringList favDirs = settings.value( "/browser/favourites" ).toStringList();
    bool inFavDirs = favDirs.contains( item->path() );

    if ( item->parent() != NULL && !inFavDirs )
    {
      // only non-root directories can be added as favourites
      menu->addAction( tr( "Add as a favourite" ), this, SLOT( addFavourite() ) );
    }
    else if ( inFavDirs )
    {
      // only favourites can be removed
      menu->addAction( tr( "Remove favourite" ), this, SLOT( removeFavourite() ) );
    }
  }

  QList<QAction*> actions = item->actions();
  if ( !actions.isEmpty() )
  {
    if ( !menu->actions().isEmpty() )
      menu->addSeparator();
    // add action to the menu
    menu->addActions( actions );
  }

  if ( menu->actions().count() == 0 )
  {
    delete menu;
    return;
  }

  menu->popup( mBrowserView->mapToGlobal( pt ) );
}
开发者ID:alepharchives,项目名称:Quantum-GIS,代码行数:44,代码来源:qgsbrowserdockwidget.cpp

示例4: mousePressEvent

void WorkspaceWidget::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::RightButton) {
        Ogre::LogManager::getSingleton().logMessage("Right mouse button clicked.");
        QPoint cursorPos = event->pos();

        QTreeWidgetItem *selItem = this->itemAt(cursorPos);
        if(selItem) {
            QString itemType = selItem->text(1);
            Ogre::LogManager::getSingleton().logMessage("Item type: " + itemType.toStdString());
        }
        QMenu *contextMenu = new QMenu(this);

        contextMenu->addAction(actionNewMaterial);
        contextMenu->popup(QWidget::mapToGlobal(cursorPos));
        return;
    }
    QTreeWidget::mousePressEvent(event);
}
开发者ID:ironsteel,项目名称:QtOME,代码行数:19,代码来源:WorkspaceWidget.cpp

示例5: listContextMenu

void MembersDialog::listContextMenu( const QPoint& pos )
{
    QModelIndex index = m_list->indexAt( pos );

    if ( index.isValid() ) {
        m_list->selectionModel()->setCurrentIndex( index, QItemSelectionModel::Current );
        m_list->selectionModel()->select( index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
    }

    QString menuName;
    if ( index.isValid() )
        menuName = "menuMember";
    else
        menuName = "menuNull";

    QMenu* menu = builder()->contextMenu( menuName );
    if ( menu )
        menu->popup( m_list->viewport()->mapToGlobal( pos ) );
}
开发者ID:Herysutrisno,项目名称:webIssue,代码行数:19,代码来源:membersdialog.cpp

示例6: showPopup

void ListView::showPopup(QTreeWidgetItem *item, QPoint p)
{
    if (item == NULL) return;
    ProcessMenuParam *mp = getMenu(item);
    if (mp == NULL)
        return;
    if (p.isNull()){
        QRect rc = visualItemRect(item);
        p = QPoint(rc.x() + rc.width() / 2, rc.y() + rc.height() / 2);
        p = viewport()->mapToGlobal(p);
    }
    mp->key	 = 0;
    Event eMenu(EventProcessMenu, mp);
    QMenu *menu = (QMenu*)eMenu.process();
    if (menu){
        setCurrentItem(item);
        menu->popup(p);
    }
}
开发者ID:BackupTheBerlios,项目名称:sim-im-svn,代码行数:19,代码来源:listview.cpp

示例7: widgetActionFocus

void tst_QMenu::widgetActionFocus()
{
    //test if the focus is correctly handled with a QWidgetAction
    QMenu m;
    QListWidget *l = new QListWidget(&m);
    for (int i = 1; i<3 ; i++)
        l->addItem(QString("item%1").arg(i));
    QWidgetAction *wa = new QWidgetAction(&m);
    wa->setDefaultWidget(l);
    m.addAction(wa);
    m.setActiveAction(wa);
    l->setFocus(); //to ensure it has primarily the focus
    QAction *menuitem1=m.addAction("menuitem1");
    QAction *menuitem2=m.addAction("menuitem2");

    m.popup(QPoint());

    QVERIFY(m.isVisible());
    QVERIFY(l->hasFocus());
    QVERIFY(l->currentItem());
    QCOMPARE(l->currentItem()->text(), QString("item1"));

    QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down);
    QVERIFY(l->currentItem());
    QCOMPARE(l->currentItem()->text(), QString("item2"));

    QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down);
    QVERIFY(m.hasFocus());
    QCOMPARE(m.activeAction(), menuitem1);

    QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down);
    QVERIFY(m.hasFocus());
    QCOMPARE(m.activeAction(), menuitem2);

    QTest::keyClick(QApplication::focusWidget(), Qt::Key_Up);
    QVERIFY(m.hasFocus());
    QCOMPARE(m.activeAction(), menuitem1);

    QTest::keyClick(QApplication::focusWidget(), Qt::Key_Up);
    QVERIFY(l->hasFocus());
    QCOMPARE(m.activeAction(), (QAction *)wa);
}
开发者ID:,项目名称:,代码行数:42,代码来源:

示例8: contextMenuEvent

/**
 * @brief Shows a popup menu with actions related to the selected item.
 * @param event The event to handle.
 */
void DialogsTreeView::contextMenuEvent(QContextMenuEvent *event) {

  if (model == nullptr) {
    return;
  }

  QMenu* menu = new QMenu(this);
  menu->addAction(create_action);

  QString id = model->get_selected_id();
  if (model->prefix_exists(id)) {
    menu->addSeparator();
    menu->addAction(set_id_action);
    menu->addAction(duplicate_action);
    menu->addSeparator();
    menu->addAction(delete_action);
  }

  menu->popup(viewport()->mapToGlobal(event->pos()) + QPoint(1, 1));
}
开发者ID:christopho,项目名称:solarus-quest-editor,代码行数:24,代码来源:dialogs_tree_view.cpp

示例9: contextMenuEvent

/*!\reimp
*/
void QLabel::contextMenuEvent(QContextMenuEvent *ev)
{
#ifdef QT_NO_CONTEXTMENU
    Q_UNUSED(ev);
#else
    Q_D(QLabel);
    if (!d->isTextLabel) {
        ev->ignore();
        return;
    }
    QMenu *menu = d->createStandardContextMenu(ev->pos());
    if (!menu) {
        ev->ignore();
        return;
    }
    ev->accept();
    menu->setAttribute(Qt::WA_DeleteOnClose);
    menu->popup(ev->globalPos());
#endif
}
开发者ID:crobertd,项目名称:qtbase,代码行数:22,代码来源:qlabel.cpp

示例10: contextMenuEvent

void ListView::contextMenuEvent(QContextMenuEvent* e)
{
    unsigned long id;
    void *param;

    ListViewItem* item = itemAt(e->pos());
    if (item == NULL)
        return;

    if (!getMenu(item, id, param))
        return;
    EventMenuProcess eMenu(id, param);
    eMenu.process();
    QMenu *menu = eMenu.menu();
    if (menu)
    {
        setCurrentItem(item);
        menu->popup(e->globalPos());
    }
}
开发者ID:BackupTheBerlios,项目名称:sim-im-svn,代码行数:20,代码来源:listview.cpp

示例11: showBookmarksPopupMenu

void ResourcesBrowser::showBookmarksPopupMenu( const QPoint& pos )
{
   QListWidgetItem* clickedItem = m_bookmarks->itemAt( pos );
   if ( !clickedItem )
   {
      // no item was clicked - ignore
      return;
   }

   // create the menu
   QMenu* popupMenu = new QMenu( this );
   {
      QAction* removeBookmarkAction = new RemoveBookmarkAction( QIcon( m_iconsDir + "removeBookmark.png" ), "Remove", this, m_bookmarks, clickedItem );
      connect( removeBookmarkAction, SIGNAL( triggered() ), this, SLOT( removeBookmark() ) );
      popupMenu->addAction( removeBookmarkAction );
   }

   // display the menu
   popupMenu->popup( mapToGlobal( pos ) );
}
开发者ID:chenwenbin928,项目名称:tamy,代码行数:20,代码来源:ResourcesBrowser.cpp

示例12: createPopupMenu

void ResTable::createPopupMenu(const QPoint& pos)
{
    LOGDEB(("ResTable::createPopupMenu: m_detaildocnum %d\n", m_detaildocnum));
    if (m_detaildocnum >= 0 && m_model) {
	int opts = m_ismainres? ResultPopup::isMain : 0;
    
	int selsz = tableView->selectionModel()->selectedRows().size();

	if (selsz == 1) {
	    opts |= ResultPopup::showSaveOne;
	} else if (selsz > 1 && !m_ismainres) {
	    // We don't show save multiple for the main list because not all 
	    // docs are necessary subdocs and multisave only works with those.
	    opts |= ResultPopup::showSaveSel;
	}
	QMenu *popup = ResultPopup::create(this, opts, m_model->getDocSource(),
					   m_detaildoc);
	popup->popup(mapToGlobal(pos));
    }
}
开发者ID:norandom,项目名称:recoll,代码行数:20,代码来源:restable.cpp

示例13: directory_ready

void Path_button::directory_ready(File_info_list files) {
  if (!menu_pending) return;
  QMenu* menu = new QMenu();
  if (go_parent_visible) {
    menu->addAction("Go to parent", this, SLOT(action_go_parent_triggered()));
    menu->addSeparator();
  }
  foreach(File_info i, files) {
    if (i.is_folder()) {
      QAction* a = menu->addAction(i.name, this, SLOT(menu_action_triggered()));
      if (i.uri == uri) {
        a->setEnabled(false);
      }
      a->setData(i.uri);
      menu->addAction(a);
    }
  }

  menu->popup(menu_point);
  menu_pending = false;
}
开发者ID:bigbn,项目名称:ridual,代码行数:21,代码来源:Path_button.cpp

示例14: contextMenuEvent

/**
 * @brief Shows a popup menu with actions related to the selected item.
 * @param event The event to handle.
 */
void SpriteTreeView::contextMenuEvent(QContextMenuEvent *event) {

  if (model == nullptr) {
    return;
  }

  QMenu* menu = new QMenu(this);
  menu->addAction(create_animation_action);

  SpriteModel::Index index = model->get_selected_index();
  if (index.is_valid()) {
    menu->addAction(create_direction_action);
    menu->addSeparator();
    menu->addAction(rename_animation_action);
    menu->addAction(duplicate_action);
    menu->addSeparator();
    menu->addAction(delete_action);
  }

  menu->popup(viewport()->mapToGlobal(event->pos()) + QPoint(1, 1));
}
开发者ID:christopho,项目名称:solarus-quest-editor,代码行数:25,代码来源:sprite_tree_view.cpp

示例15: customContextMenuRequested

void USBLinkTreeWidget::customContextMenuRequested(QPoint pos)
{
    QMenu *menu = new QMenu(this);
    QAction *action_delete = new QAction(tr("Delete"), menu);

    context_menu_item = this->itemAt(pos);

    if(context_menu_item == nullptr || context_menu_item->data(0, Qt::UserRole).toBool() == true)
    {
        // Is a directory
        QWidgetAction *action_new_folder = new QWidgetAction(menu);
        QLineEdit *line_new_folder = new QLineEdit(nullptr);
        line_new_folder->setPlaceholderText(tr("New folder"));
        action_new_folder->setDefaultWidget(line_new_folder);

        connect(line_new_folder, &QLineEdit::returnPressed, this, &USBLinkTreeWidget::newFolder);
        // FIXME: Can this delete line_new_folder while in use by newFolder?
        connect(line_new_folder, &QLineEdit::returnPressed, menu, &QMenu::close);

        menu->addAction(action_new_folder);

        if(context_menu_item == nullptr || context_menu_item->childCount() > 0)
        {
            // Non-empty directory
            action_delete->setDisabled(true);
        }
    }
    else
    {
        // Is not a directory
        QAction *action_download = new QAction(tr("Download"), menu);
        connect(action_download, &QAction::triggered, this,  &USBLinkTreeWidget::downloadEntry);
        menu->addAction(action_download);
    }

    connect(action_delete, &QAction::triggered, this,  &USBLinkTreeWidget::deleteEntry);
    menu->addAction(action_delete);

    menu->popup(this->viewport()->mapToGlobal(pos));
}
开发者ID:GoGadgetGo,项目名称:firebird,代码行数:40,代码来源:usblinktreewidget.cpp


注:本文中的QMenu::popup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。