本文整理汇总了C++中QMenu::font方法的典型用法代码示例。如果您正苦于以下问题:C++ QMenu::font方法的具体用法?C++ QMenu::font怎么用?C++ QMenu::font使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMenu
的用法示例。
在下文中一共展示了QMenu::font方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findStack
// Search through the list of known stack menu items & find the menu for
// this notebook's stack. If one doesn't exist we add it.
QMenu* NotebookMenuButton::findStack(Notebook n) {
if (!n.__isset.stack || QString::fromStdString(n.stack).trimmed() == "")
return &rootMenu;
QString stack = QString::fromStdString(n.stack).trimmed();
for (int i=0; i<stackMenus.size(); i++) {
if (stackMenus.at(i)->title().toLower() == stack.toLower())
return stackMenus.at(i);
}
// Create a new stack. We add a dummy action item to the
// menu so we know where to add the menu later. This
// keeps things in sorted order
QMenu *newMenu = new QMenu(this);
newMenu->setTitle(stack);
QFont f = newMenu->font();
f.setPointSize(10);
f.setBold(false);
newMenu->setFont(f);
stackMenus.append(newMenu);
QAction *placeHolder = new QAction(this);
placeHolder->setVisible(false);
placeHolder->setText(stack);
addNotebookMenuItem(&rootMenu, placeHolder);
addStackMenuItem(newMenu);
return newMenu;
}
示例2: createTitle
void MenuFactory::createTitle(
QMenu& menu,
const QString& title )
{
QAction* pItem = menu.addAction( title );
QFont font = menu.font();
font.setBold( true );
pItem->setFont( font );
pItem->setEnabled( false );
}
示例3: itemMenu
void MainWindow::itemMenu(QPoint pos)
{
QMenu* menu = new QMenu(this);
auto selection = ui->tableView->selectionModel();
auto message = ui->tableView->message(selection->currentIndex().row());
if (message)
{
QList<PathRec> paths;
auto text = message->originalMessage.toHtmlEscaped();
findPaths(text, paths);
for (int i = 0; i < paths.size(); ++i)
{
menu->addAction(paths[i].path, this, "uurlClicked()");
}
if (paths.size())
{
menu->addSeparator();
}
if (auto logModel = dynamic_cast<LogModel*>(ui->tableView->sourceModel()))
{
LogModel::Client client;
if (logModel->clientFromMessage(*message, client))
{
QFontMetrics metrics(menu->font());
auto path = metrics.elidedText(client.path(), Qt::ElideMiddle, 200);
auto name = QString("Disconnect [%1] %2").arg(client.pid()).arg(path);
auto action = new QAction(name, this);
action->setProperty("socket", quint64(client.socket()));
connect(action, &QAction::triggered, this, &MainWindow::disconnectClient);
menu->addAction(action);
menu->addSeparator();
}
}
}
menu->addAction(ui->actionClear);
menu->exec(ui->tableView->mapToGlobal(pos));
delete menu;
}
示例4: showContextMenu
void MusicListView::showContextMenu(const QPoint &pos,
PlaylistPtr selectedPlaylist,
PlaylistPtr favPlaylist,
QList<PlaylistPtr> newPlaylists)
{
Q_D(MusicListView);
QItemSelectionModel *selection = this->selectionModel();
if (selection->selectedRows().length() <= 0) {
return;
}
QPoint globalPos = this->mapToGlobal(pos);
QMenu playlistMenu;
playlistMenu.setStyle(QStyleFactory::create("dlight"));
auto newvar = QVariant::fromValue(PlaylistPtr());
auto createPlaylist = playlistMenu.addAction(tr("New playlist"));
createPlaylist->setData(newvar);
createPlaylist->setIcon(QIcon(":/light/image/plus.svg"));
playlistMenu.addSeparator();
if (selectedPlaylist != favPlaylist) {
auto act = playlistMenu.addAction(favPlaylist->displayName());
act->setData(QVariant::fromValue(favPlaylist));
}
for (auto playlist : newPlaylists) {
QFont font(playlistMenu.font());
QFontMetrics fm(font);
auto text = fm.elidedText(QString(playlist->displayName().replace("&", "&&")),
Qt::ElideMiddle, 160);
auto act = playlistMenu.addAction(text);
act->setData(QVariant::fromValue(playlist));
}
connect(&playlistMenu, &QMenu::triggered, this, [ = ](QAction * action) {
auto playlist = action->data().value<PlaylistPtr >();
qDebug() << playlist;
MetaPtrList metalist;
for (auto &index : selection->selectedRows()) {
auto meta = d->model->meta(index);
if (!meta.isNull()) {
metalist << meta;
}
}
Q_EMIT addToPlaylist(playlist, metalist);
});
bool singleSelect = (1 == selection->selectedRows().length());
QMenu myMenu;
myMenu.setStyle(QStyleFactory::create("dlight"));
QAction *playAction = nullptr;
if (singleSelect) {
playAction = myMenu.addAction(tr("Play"));
}
myMenu.addAction(tr("Add to playlist"))->setMenu(&playlistMenu);
myMenu.addSeparator();
QAction *displayAction = nullptr;
if (singleSelect) {
displayAction = myMenu.addAction(tr("Display in file manager"));
}
auto removeAction = myMenu.addAction(tr("Remove from playlist"));
auto deleteAction = myMenu.addAction(tr("Delete from local disk"));
QAction *songAction = nullptr;
QMenu textCodecMenu;
textCodecMenu.setStyle(QStyleFactory::create("dlight"));
if (singleSelect) {
auto index = selection->selectedRows().first();
auto meta = d->model->meta(index);
QList<QByteArray> codecList = DMusic::detectMetaEncodings(meta);
// codecList << "utf-8" ;
for (auto codec : codecList) {
auto act = textCodecMenu.addAction(codec);
act->setData(QVariant::fromValue(codec));
}
if (codecList.length() > 1) {
myMenu.addSeparator();
myMenu.addAction(tr("Encoding"))->setMenu(&textCodecMenu);
}
myMenu.addSeparator();
songAction = myMenu.addAction(tr("Song info"));
connect(&textCodecMenu, &QMenu::triggered, this, [ = ](QAction * action) {
auto codec = action->data().toByteArray();
meta->updateCodec(codec);
Q_EMIT updateMetaCodec(meta);
});
//.........这里部分代码省略.........
示例5: editorContextMenuRequested
//.........这里部分代码省略.........
if (element.isContentSelected()) {
if (!menu->isEmpty())
menu->addSeparator();
menu->addAction(ui->editor->pageAction(QWebPage::Copy));
if (element.isContentEditable()) {
menu->addAction(ui->editor->pageAction(QWebPage::Cut));
menu->addAction(ui->editor->pageAction(QWebPage::Paste));
menu->addSeparator();
menu->addAction(ui->editor->pageAction(QWebPage::ToggleBold));
menu->addAction(ui->editor->pageAction(QWebPage::ToggleItalic));
menu->addAction(ui->editor->pageAction(QWebPage::ToggleUnderline));
}
}
if(!element.imageUrl().isEmpty() && (element.imageUrl().scheme() != "qrc")) {
if (!menu->isEmpty())
menu->addSeparator();
menu->addAction(ui->editor->pageAction(QWebPage::DownloadImageToDisk));
menu->addAction(ui->editor->pageAction(QWebPage::CopyImageToClipboard));
if (element.imageUrl().scheme() == "http" || element.imageUrl().scheme() == "https")
menu->addAction(ui->editor->pageAction(QWebPage::CopyImageUrlToClipboard));
QAction * openImage = new QAction(this);
openImage->setText("Open Image");
openImage->setObjectName("openImage");
menu->addAction(openImage);
if (JS("editMode").toBool()) {
menu->addSeparator();
QAction * deleteImage = new QAction(this);
deleteImage->setText("Delete Image");
deleteImage->setObjectName("deleteImage");
deleteImage->setIcon(QIcon::fromTheme("edit-delete"));
menu->addAction(deleteImage);
if (element.imageUrl().scheme() != "resource") {
QAction * saveLocally = new QAction(this);
saveLocally->setText("Save Locally");
saveLocally->setObjectName("saveLocally");
menu->addAction(saveLocally);
}
}
}
if (!element.linkUrl().isEmpty()) {
if (!menu->isEmpty())
menu->addSeparator();
menu->addAction(ui->editor->pageAction(QWebPage::CopyLinkToClipboard));
if (element.isContentEditable()) {
QAction * deleteURL = new QAction(this);
deleteURL->setText("Remove Link");
deleteURL->setObjectName("deleteURL");
menu->addAction(deleteURL);
}
}
if (element.isContentEditable() && !element.isContentSelected() && element.imageUrl().isEmpty()) {
Speller *speller = Speller::GetInstance();
if (speller->initialized()) {
QHash<QString, QString> languages = speller->availableLanguages();
if (!languages.isEmpty()) {
if (!menu->isEmpty())
menu->addSeparator();
QAction* act = menu->addAction(tr("Check &Spelling"));
act->setCheckable(true);
act->setChecked(speller->isEnabled());
connect(act, SIGNAL(triggered(bool)), speller, SLOT(setEnabled(bool)));
if (speller->isEnabled()) {
QString word = JS(QString("getSpellingWord(%1,%2);").arg(pos.x()).arg(pos.y())).toString();
if (!word.isEmpty() && speller->isMisspelled(word)) {
QStringList wordsList = speller->suggest(word);
QFont boldFont = menu->font();
boldFont.setBold(true);
QActionGroup *suggestGroup = new QActionGroup(menu);
QString suggest;
foreach(suggest, wordsList) {
QAction* act = menu->addAction(suggest);
act->setFont(boldFont);
act->setData(suggest);
suggestGroup->addAction(act);
}
connect(suggestGroup, SIGNAL(triggered(QAction*)), this, SLOT(replaceWord(QAction*)));
}
示例6: paintEvent
void KxMenuItemWidget::paintEvent(QPaintEvent *event)
{
// Do not draw invisible menu items
if(!fMenuItem->isVisible()) return;
QStylePainter painter(this);
QStyleOptionMenuItem opt = getStyleOption();
QRect boxRect;
bool inOptionBox = false;
QWidget *q = parentWidget();
const int hmargin = q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, q),
iconWidth = q->style()->pixelMetric(QStyle::PM_SmallIconSize, 0, q);
if(!fMenuItem->isSeparator()) {
if(fMenuItem->hasOptionBox()) {
boxRect.setRect(rect().right() - hmargin - iconWidth, rect().top(), iconWidth, rect().height());
QPoint p = QCursor::pos();
p = mapFromGlobal(p);
if(boxRect.contains(p)) {
inOptionBox = true;
} else {
// Subtract option box rect from style option rect
int newRight = opt.rect.right() - iconWidth - hmargin;
opt.rect.setRight(newRight);
}
}
}
// Draw general menu item
opt.rect.adjust(0, 0, -1, 0);
painter.drawControl(QStyle::CE_MenuItem, opt);
// Draw shortcut
QKeySequence shortcutSeq = fMenuItem->shortcut();
if(!shortcutSeq.isEmpty()) {
// shortcut bounds
QRect scRect = opt.rect;
QString shortcut = shortcutSeq.toString(QKeySequence::NativeText);
QMenu *menu = qobject_cast<QMenu *>(parentWidget());
Q_ASSERT(menu != NULL);
int shortcutWidth = 12; // default value in case there is no font
if ( menu ) {
QFontMetrics metrics(fMenuItem->font().resolve(menu->font()));
shortcutWidth = metrics.width(shortcut);
}
scRect.setLeft(scRect.right() - shortcutWidth);
if(inOptionBox || !fMenuItem->hasOptionBox()) {
scRect.translate(-iconWidth, 0);
}
scRect.translate(-kShortcutRightMargin, 0);
painter.drawItemText(scRect, Qt::AlignRight | Qt::AlignVCenter, palette(), true, shortcut);
}
// Draw option box
if(!fMenuItem->isSeparator() && fMenuItem->hasOptionBox()) {
QIcon* boxIcon = NULL;
QVariant v = fMenuItem->optionBoxAction()->property( "optionBoxIcon" );
if ( v.isValid() ) {
QString optionBoxIcon;
optionBoxIcon = v.toString();
boxIcon = KxQtHelper::createIcon( optionBoxIcon );
}
if ( boxIcon == NULL ) {
boxIcon = new QIcon(":/optionBox.png");
}
boxRect.setRect(rect().right() - hmargin - iconWidth, rect().top()+(rect().height()-iconWidth)/2, iconWidth, iconWidth);
boxIcon->paint(&painter, boxRect, Qt::AlignCenter, fMenuItem->isEnabled() ? QIcon::Normal : QIcon::Disabled);
delete boxIcon;
}
}