我開發的Qt應用程序,我有從托盤圖標恢復窗口的問題。恢復窗口位置
這裏是與托盤圖標連接的代碼:
createActions();
createTrayIcon();
setIcon();
trayIcon->show();
connect(
trayIcon,
SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this,
SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason))
);
創建操作
open = new QAction(tr("&Open"), this);
connect(open, SIGNAL(triggered()), this, SLOT(show()));
close = new QAction(tr("&Quit"), this);
connect(close, SIGNAL(triggered()),qApp, SLOT(quit()));
void MainWindow::createTrayIcon()
{
trayIconMenu = new QMenu(this);
trayIconMenu->addAction(open);
trayIconMenu->addSeparator();
trayIconMenu->addAction(close);
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
}
void MainWindow::trayIconClicked(QSystemTrayIcon::ActivationReason reason)
{
if(reason == QSystemTrayIcon::Trigger)
this->show();
}
void MainWindow::closeEvent(QCloseEvent *event)
{
QString title = "Smart Typer 2000";
QString text = "Aplikácia stále beží, obnovíte ju poklepením po ikonke, zrušíte ju stlačením ikonky pravým tlačítkom,"
"a následným zvolením možnosti Quit";
if (trayIcon->isVisible()) {
trayIcon->showMessage(title,text,QSystemTrayIcon::Information,5000);
trayIcon->setToolTip("Smart Typer 2000");
this->setVisible(false);
event->ignore(); // Don't let the event propagate to the base class
}
}
所以,當我點擊在主窗口[x]按鈕,應用程序是發送到托盤圖標,當我點擊這個托盤圖標,在主窗口的大小和位置被恢復,這是很好的。
但是當我按下[_]鍵,應用程序最小化,無論是任務欄圖標,系統托盤圖標是可見的,並單擊托盤圖標後,應用程序主窗口不會恢復本身。 (也窗口即使我上右鍵托盤圖標單擊,然後選擇不會自行恢復「打開」選項)
我嘗試過各種東西一樣,而不是
this->show();
我試圖調用
this->showNormal();
唯一的一次,當恢復窗口,當我叫
this->showMaximized();
的
當然,主窗口是真正最大化的,這並不是很好,所以我將最大寬度和最大高度設置爲默認的應用程序維度(我不介意,因爲我的應用程序不需要更大),但是... 雖然窗戶被恢復,規模還是不錯的,位置沒有,窗戶是在我的顯示器的左上角,這有點兒鬧心恢復。 所以,我想利用這段代碼 http://doc.qt.io/archives/qt-4.7/restoring-geometry.html
我對隱藏和關閉的事件保存窗口狀態和幾何形狀,然後,我嘗試被點擊托盤圖標時恢復它,但沒有成功..
所以,你有什麼想法 ?窗口最小化時如何通過點擊trayicon來恢復窗口?
您的問題與托盤無關,因爲最小化窗口不涉及托盤。請顯示您用來保存/恢復窗口幾何的代碼。 – Koying 2012-03-13 12:17:47
我的問題是關係到托盤,我想與點擊托盤圖標,當我以前單擊[_]鍵恢復窗口。當按下[X]按鈕時,我可以通過點擊托盤圖標來恢復窗口。並且處理這個的代碼在函數中void MainWindow :: trayIconClicked(QSystemTrayIcon :: ActivationReason reason); (代碼在上面) – 2012-03-13 12:39:50
是http://stackoverflow.com/questions/3332257/how-do-i-properly-implement-a-minimize-to-tray-function-in-qt/6094872你在找什麼對於? – Manjabes 2012-03-13 12:48:47