菜单应该如何弹出 - Qt
我正在读一本关于Qt的书,有一个关于如何弹出历史菜单的例子,文本说“当调用此方法时,它会弹出一个菜单,其项目对应于用户访问过的网页”,
但是我真的不明白我们如何使“菜单”可见:这是 SLOT 方法:
void BrowerWindow::popupHistoryMenu()
{
QMenu menu;
…
QListIterator<QWebHistoryItem> i(webView->history()->items());
i.toBack();
while(i.hasPrevious() && … )
{
const QWebHistoryItem & item = i.previous();
QString title = ...
QAction *action = new QAction(item.icon(), title, &menu);
action->setData(item.url());
menu.addAction(action);
}
AQP::accelerateMenu(&menu);
if (QAction *action = menu.exec(QCursor::pos()))
webView->load(action->data().toUrl());
}
所以我不明白如何从这个简单的功能中弹出菜单? (“调用此方法时会弹出一个菜单”)
谢谢
i'm reading a book about Qt, there is an example about how to pop up the history menu, the text says "when this method is invoked it pops up a menu whose items correspond to the web pages the user has visited",
but i don't really see how we make the "menu" visible : here's the SLOT method:
void BrowerWindow::popupHistoryMenu()
{
QMenu menu;
…
QListIterator<QWebHistoryItem> i(webView->history()->items());
i.toBack();
while(i.hasPrevious() && … )
{
const QWebHistoryItem & item = i.previous();
QString title = ...
QAction *action = new QAction(item.icon(), title, &menu);
action->setData(item.url());
menu.addAction(action);
}
AQP::accelerateMenu(&menu);
if (QAction *action = menu.exec(QCursor::pos()))
webView->load(action->data().toUrl());
}
So i don't see how the menu can be popped up from that simple function?
( "when this method is invoked it pops up a menu" )
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 QMenu 的文档(具体来说,QMenu.exec())所说,它有效吗?
http://doc.qt.io/qt-5/qmenu.html #exec-2
您发布的代码中的相关行:
Exactly as the docs for
QMenu
(specifically,QMenu.exec()
) say it works?http://doc.qt.io/qt-5/qmenu.html#exec-2
Relevant line in the code you posted: