本文整理汇总了C++中QSystemTrayIcon::setVisible方法的典型用法代码示例。如果您正苦于以下问题:C++ QSystemTrayIcon::setVisible方法的具体用法?C++ QSystemTrayIcon::setVisible怎么用?C++ QSystemTrayIcon::setVisible使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSystemTrayIcon
的用法示例。
在下文中一共展示了QSystemTrayIcon::setVisible方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
QApplication app(argc, argv);
KAboutData about("kdeconnect-cli",
i18n("KDE Connect Indicator"),
QStringLiteral(KDECONNECT_VERSION_STRING),
i18n("KDE Connect Indicator tool"),
KAboutLicense::GPL,
i18n("(C) 2016 Aleix Pol Gonzalez"));
KAboutData::setApplicationData(about);
DevicesModel model;
model.setDisplayFilter(DevicesModel::Reachable | DevicesModel::Paired);
QMenu menu;
auto configure = menu.addAction(i18n("Configure..."));
QObject::connect(configure, &QAction::triggered, configure, [](){
QProcess::startDetached("kcmshell5", {"kdeconnect"});
});
QSystemTrayIcon systray;
systray.setIcon(QIcon::fromTheme("kdeconnect"));
systray.setContextMenu(&menu);
systray.setVisible(true);
QObject::connect(&model, &DevicesModel::rowsInserted, &model, [&menu, &model](const QModelIndex& /*parent*/, int first, int last) {
for (int i=first; i<=last; ++i) {
DeviceDbusInterface* device = model.getDevice(i);
auto indicator = new DeviceIndicator(device);
QObject::connect(device, &DeviceDbusInterface::destroyed, indicator, &QObject::deleteLater);
menu.addMenu(indicator);
}
});
QObject::connect(&model, &DevicesModel::rowsChanged, &model, [&systray, &model]() {
systray.setToolTip(i18np("%1 device connected", "%1 devices connected", model.rowCount()));
});
return app.exec();
}
示例2: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
const QString app_name("timecop");
const QString app_version("1.1");
const QString app_settings_dir(QDir::home().filePath(".timecop"));
app.setOrganizationName("Daimler AG RD-DDA");
app.setApplicationName(app_name);
QSettings::setDefaultFormat(QSettings::IniFormat);
QSettings::setPath(QSettings::IniFormat,
QSettings::UserScope,
app_settings_dir);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QObject *root = 0;
QWidget *rootWindow = 0;
SystrayHelper systrayHelper;
engine.rootContext()->setContextProperty("systrayHelper", &systrayHelper);
engine.rootContext()->setContextProperty("app_name", app_name);
engine.rootContext()->setContextProperty("app_version", app_version);
engine.rootContext()->setContextProperty("app_settings_dir", app_settings_dir);
if (engine.rootObjects().size() > 0)
{
root = engine.rootObjects().at(0);
systrayHelper.setRootWindow(root);
if(root->isWindowType()){
rootWindow = qobject_cast<QWidget*>(root);
QApplication::setQuitOnLastWindowClosed(false);
QAction *minimizeAction = new QAction(QObject::tr("Mi&nimize"), rootWindow);
rootWindow->connect(minimizeAction, SIGNAL(triggered()), root, SLOT(hide()));
QAction *maximizeAction = new QAction(QObject::tr("Ma&ximize"), rootWindow);
rootWindow->connect(maximizeAction, SIGNAL(triggered()), root, SLOT(showMaximized()));
QAction *restoreAction = new QAction(QObject::tr("&Restore"), rootWindow);
rootWindow->connect(restoreAction, SIGNAL(triggered()), root, SLOT(showNormal()));
QAction *quitAction = new QAction(QObject::tr("&Quit"), rootWindow);
rootWindow->connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
QMenu *trayIconMenu = new QMenu(rootWindow);
trayIconMenu->addAction(minimizeAction);
trayIconMenu->addAction(maximizeAction);
trayIconMenu->addAction(restoreAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
QSystemTrayIcon *trayIcon = new QSystemTrayIcon(rootWindow);
QIcon icon(":/trayicon.png");
icon.setIsMask(true);
//trayIcon->setContextMenu(trayIconMenu);
trayIcon->setIcon(icon);
trayIcon->setToolTip("Click to open");
trayIcon->setVisible(true);
systrayHelper.setTrayIcon(trayIcon);
QObject::connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), &systrayHelper, SLOT(activatedSystray(QSystemTrayIcon::ActivationReason)));
trayIcon->show();
}
}
return app.exec();
}