1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| void MainWindow::createSystemTrayIcon() { trayIcon=new QSystemTrayIcon(this); trayIcon->setIcon(QIcon(tr(":images/icon"))); trayIcon->setToolTip(tr("托盘")); play_widget = new QWidget(); play_widget_Action = new QWidgetAction(this); play_Button = new QPushButton(); play_Button ->setCursor(Qt::PointingHandCursor); play_Button ->setFlat(true); play_Button->setFixedSize(40,40); connect(play_Button,SIGNAL(clicked()), this, SLOT(Play())); last_Button = new QPushButton(); last_Button ->setCursor(Qt::PointingHandCursor); last_Button ->setFlat(true); last_Button->setFixedSize(30,30); connect(last_Button, SIGNAL(clicked()), this, SLOT(Last())); next_Button = new QPushButton(); next_Button->setCursor(Qt::PointingHandCursor); next_Button ->setFlat(true); next_Button->setFixedSize(30,30); connect(next_Button, SIGNAL(clicked()), this, SLOT(Next())); musicname_Label = new QLabel(); musicname_Label->setFixedWidth(100); musicname_Label->setAlignment(Qt::AlignCenter); aboutAction = new QAction(tr("关 于"),this); aboutAction->setIcon(QIcon(":/images/about")); connect(aboutAction,SIGNAL(triggered()),this,SLOT(about())); quitAction=new QAction(tr("退 出"), this); quitAction->setIcon(QIcon(":/images/quit")); connect(quitAction, SIGNAL(triggered()), this, SLOT(quit()));
last_Button->setStyleSheet("QPushButton {border-image:url(:/images/last);}QPushButton:hover{border-image:url(:/images/last_on);}QPushButton:hover:pressed{border-image:url(:/images/last);}"); play_Button->setStyleSheet("QPushButton {border-image:url(:/images/play);}QPushButton:hover{border-image:url(:/images/play_on);}QPushButton:hover:pressed{border-image:url(:/images/play);}"); next_Button->setStyleSheet("QPushButton {border-image:url(:/images/next);}QPushButton:hover{border-image:url(:/images/next_on);}QPushButton:hover:pressed{border-image:url(:/images/next);}");
QHBoxLayout *Hlayout = new QHBoxLayout(); Hlayout->addWidget(last_Button); Hlayout->addWidget(play_Button); Hlayout->addWidget(next_Button); Hlayout->setSpacing(0); Hlayout->setContentsMargins(20, 0, 20, 0);
QVBoxLayout *Vlayout = new QVBoxLayout(); Vlayout->addLayout(Hlayout); Vlayout->addWidget(musicname_Label,0,Qt::AlignCenter); Vlayout->setSpacing(5); Vlayout->setContentsMargins(0, 0, 0, 5); musicname_Label->setEnabled(false);
play_widget->setLayout(Vlayout); play_widget_Action->setDefaultWidget(play_widget);
trayContextMenu=new QMenu(this); trayContextMenu->addAction(play_widget_Action); trayContextMenu->addSeparator(); trayContextMenu->addAction(aboutAction); trayContextMenu->addAction(quitAction);
trayIcon->setContextMenu(trayContextMenu); trayIcon->show();
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); }
|