本文整理汇总了C++中QMenu::setStyle方法的典型用法代码示例。如果您正苦于以下问题:C++ QMenu::setStyle方法的具体用法?C++ QMenu::setStyle怎么用?C++ QMenu::setStyle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMenu
的用法示例。
在下文中一共展示了QMenu::setStyle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
});
//.........这里部分代码省略.........