本文整理汇总了C++中QMenu::installEventFilter方法的典型用法代码示例。如果您正苦于以下问题:C++ QMenu::installEventFilter方法的具体用法?C++ QMenu::installEventFilter怎么用?C++ QMenu::installEventFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMenu
的用法示例。
在下文中一共展示了QMenu::installEventFilter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: menuCreate
void CLoginButton::menuCreate() {
QMenu* menu = new QMenu(this);
QWidget *w = new QWidget(this);
ui = new Ui::loginWidget;
ui->setupUi(w);
ui->toolButton->setEnabled(false);
connect(ui->lineEdit, &QLineEdit::textChanged,
this, &CLoginButton::usernameCheck);
connect(ui->toolButton, &QToolButton::clicked,
this, &CLoginButton::login);
QVBoxLayout *vlayout = new QVBoxLayout;
vlayout->addWidget(w);
menu->setLayout(vlayout);
QPixmap pixmap(":/back/ui/back/combox.png");
menu->setMask(pixmap.mask());
menu->setStyleSheet("color:white; background-color: rgb(85, 92, 120);");
menu->installEventFilter(this);
setMenu(menu);
}
示例2: buildMenu
void KrBookmarkHandler::buildMenu(KrBookmark *parent, QMenu *menu)
{
static int inSecondaryMenu = 0; // used to know if we're on the top menu
// run the loop twice, in order to put the folders on top. stupid but easy :-)
// note: this code drops the separators put there by the user
QListIterator<KrBookmark *> it(parent->children());
while (it.hasNext()) {
KrBookmark *bm = it.next();
if (!bm->isFolder()) continue;
QMenu *newMenu = new QMenu(menu);
newMenu->setIcon(QIcon(krLoader->loadIcon(bm->iconName(), KIconLoader::Small)));
newMenu->setTitle(bm->text());
QAction *menuAction = menu->addMenu(newMenu);
QVariant v;
v.setValue<KrBookmark *>(bm);
menuAction->setData(v);
++inSecondaryMenu;
buildMenu(bm, newMenu);
--inSecondaryMenu;
}
it.toFront();
while (it.hasNext()) {
KrBookmark *bm = it.next();
if (bm->isFolder()) continue;
if (bm->isSeparator()) {
menu->addSeparator();
continue;
}
menu->addAction(bm);
CONNECT_BM(bm);
}
if (!inSecondaryMenu) {
KConfigGroup group(krConfig, "Private");
bool hasPopularURLs = group.readEntry("BM Popular URLs", true);
bool hasTrash = group.readEntry("BM Trash", true);
bool hasLan = group.readEntry("BM Lan", true);
bool hasVirtualFS = group.readEntry("BM Virtual FS", true);
bool hasJumpback = group.readEntry("BM Jumpback", true);
if (hasPopularURLs) {
menu->addSeparator();
// add the popular links submenu
QMenu *newMenu = new QMenu(menu);
newMenu->setTitle(i18n("Popular URLs"));
newMenu->setIcon(QIcon(krLoader->loadIcon("folder-bookmark", KIconLoader::Small)));
QAction *bmfAct = menu->addMenu(newMenu);
_specialBookmarks.append(bmfAct);
// add the top 15 urls
#define MAX 15
QList<QUrl> list = _mainWindow->popularUrls()->getMostPopularUrls(MAX);
QList<QUrl>::Iterator it;
for (it = list.begin(); it != list.end(); ++it) {
QString name;
if ((*it).isLocalFile()) name = (*it).path();
else name = (*it).toDisplayString();
// note: these bookmark are put into the private collection
// as to not spam the general collection
KrBookmark *bm = KrBookmark::getExistingBookmark(name, _privateCollection);
if (!bm)
bm = new KrBookmark(name, *it, _privateCollection);
newMenu->addAction(bm);
CONNECT_BM(bm);
}
newMenu->addSeparator();
newMenu->addAction(krPopularUrls);
newMenu->installEventFilter(this);
}
// do we need to add special bookmarks?
if (SPECIAL_BOOKMARKS) {
if (hasTrash || hasLan || hasVirtualFS || hasJumpback)
menu->addSeparator();
KrBookmark *bm;
// note: special bookmarks are not kept inside the _bookmarks list and added ad-hoc
if (hasTrash) {
bm = KrBookmark::trash(_collection);
menu->addAction(bm);
_specialBookmarks.append(bm);
CONNECT_BM(bm);
}
if (hasLan) {
bm = KrBookmark::lan(_collection);
menu->addAction(bm);
_specialBookmarks.append(bm);
CONNECT_BM(bm);
}
if (hasVirtualFS) {
bm = KrBookmark::virt(_collection);
menu->addAction(bm);
//.........这里部分代码省略.........
示例3: menuBookmarksAboutToShow
void MainWindow::menuBookmarksAboutToShow()
{
QMenu *menu = qobject_cast<QMenu*>(sender());
if (!menu || !menu->menuAction())
{
return;
}
menu->setObjectName(QLatin1String("bookmarks"));
menu->installEventFilter(this);
const int folder = menu->menuAction()->data().toInt();
if ((folder == 0 && menu->actions().count() == 3) || (folder != 0 && menu->actions().isEmpty()))
{
WebBackend *backend = WebBackendsManager::getBackend();
const QList<BookmarkInformation*> bookmarks = BookmarksManager::getFolder(folder);
if (folder != 0 && bookmarks.count() > 1)
{
QAction *openAllAction = menu->addAction(Utils::getIcon(QLatin1String("document-open-folder")), tr("Open All"));
openAllAction->setData(folder);
connect(openAllAction, SIGNAL(triggered()), this, SLOT(actionOpenBookmarkFolder()));
menu->addSeparator();
}
for (int i = 0; i < bookmarks.count(); ++i)
{
if (bookmarks.at(i)->type == FolderBookmark || bookmarks.at(i)->type == UrlBookmark)
{
QAction *action = menu->addAction(((bookmarks.at(i)->type == FolderBookmark) ? Utils::getIcon(QLatin1String("inode-directory")) : backend->getIconForUrl(QUrl(bookmarks.at(i)->url))), (bookmarks.at(i)->title.isEmpty() ? tr("(Untitled)") : Utils::elideText(QString(bookmarks.at(i)->title).replace(QLatin1Char('&'), QLatin1String("&&")), menu)));
action->setToolTip(bookmarks.at(i)->description);
if (bookmarks.at(i)->type == FolderBookmark)
{
action->setData(bookmarks.at(i)->identifier);
if (!bookmarks.at(i)->children.isEmpty())
{
action->setMenu(new QMenu());
connect(action->menu(), SIGNAL(aboutToShow()), this, SLOT(menuBookmarksAboutToShow()));
}
}
else
{
action->setData(bookmarks.at(i)->url);
connect(action, SIGNAL(triggered()), this, SLOT(actionOpenBookmark()));
}
}
else
{
menu->addSeparator();
}
}
}
}