ich habe ein kleines Programmzusammengesteckt.
Dazu habe ich eine Klasse von QSystemTrayIcon abgeleitet --> foo.c, foo.cpp
Ziel der Sache ist, dass ein TrayIcon unabhängit läuft, MessageIO über Ballons und Steuerung über das Context Menu.
Grundsätzlich geht das auch hervorragend:
Code: Alles auswählen
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
QMessageBox::critical(0, QObject::tr("Systray"),
QObject::tr("I couldn't detect any system tray "
"on this system."));
return 1;
}
foo foo;
foo.show();
return app.exec();
}
Code: Alles auswählen
foo::foo()
{
m_IconMessage = new QIcon("Message.gif");
// Create Tray
m_ShowStatus = new QAction(tr("Show Status"), this);
m_Quit = new QAction(tr("Quit"), this);
connect(m_ShowStatus, SIGNAL(triggered()), this, SLOT(onCmdShowStatus()) );
connect(m_Quit, SIGNAL(triggered()), qApp, SLOT(quit()));
m_TrayIconMenu = new QMenu();
m_TrayIconMenu->addAction(m_ShowStatus);
m_TrayIconMenu->addSeparator();
m_TrayIconMenu->addAction(m_Quit);
setContextMenu(m_TrayIconMenu);
setIcon(*m_IconMessage);
}
Code: Alles auswählen
void foo::onCmdShowStatus()
{
QString p_StatusText = "uhaha";
QTextEdit *p_Status = new QTextEdit();
p_Status->setParent(NULL);
p_Status->setFont(QFont("Courier",12));
p_Status->setText(p_StatusText);
p_Status->setReadOnly(true);
p_Status->show();
p_Status->setGeometry(100, 100, 1200, 600);
}
2. Frage: Die kann ich kein einem QSystemTrayIcon eine "relative Uhr" realisieren? Ich kann (von woanders) im Moment einen Timer starten, der der ändert jede Sekunde das Tooltip des TrayIcon auf die akutelle Zeit. Effizienter wäre aber, wenn ich den Tooltipp der onDemand, also onMouseOver schreibe. Aber wie merke ich das (welches Signal)? Schön wäre auch, wenn die Uhr weiterläuft, während die Maus auf dem Icon steht.
Code: Alles auswählen
void foo::onCmdSetTimer(int i_Minutes)
{
connect(m_Timer, SIGNAL(timeout()), this, SLOT(onCmdTimerEvent()) );
m_Timer->start(1000);
m_StartTime = QTime::currentTime();
m_TimerMinutes = i_Minutes;
}
void foo::onCmdTimerEvent()
{
QTime p_CurrentTime = QTime::currentTime();
p_CurrentTime = m_StartTime.addSecs(-p_CurrentTime.second()-p_CurrentTime.minute()*60-p_CurrentTime.hour()*60*60);
p_CurrentTime = p_CurrentTime.addSecs(m_TimerMinutes*60);
QString p_Text = p_CurrentTime.toString("hh:mm:ss");
this->setToolTip(p_Text);
}
Gruß,
curator