解决pc模式任务栏无网络图标问题

This commit is contained in:
zhangyuanyuan1 2023-01-06 15:22:26 +08:00
parent f7c2f58202
commit 21869cc2e8
2 changed files with 29 additions and 4 deletions

View File

@ -115,6 +115,7 @@ void MainWindow::firstlyStart()
{ {
initWindowProperties(); initWindowProperties();
initTransparency(); initTransparency();
registerTrayIcon();
initUI(); initUI();
initDbusConnnect(); initDbusConnnect();
initWindowTheme(); initWindowTheme();
@ -265,6 +266,30 @@ void MainWindow::initUI()
paintWithTrans(); paintWithTrans();
} }
/**
* @brief MainWindow::registerTrayIcon
*/
void MainWindow::registerTrayIcon()
{
m_registerCount++;
if (QSystemTrayIcon::isSystemTrayAvailable() || m_registerCount > 10) {
m_trayIcon = new QSystemTrayIcon();
if (nullptr == m_trayIcon) {
qWarning()<< "分配空间trayIcon失败";
return ;
}
m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic"));
m_trayIcon->setToolTip(QString(tr("kylin-nm")));
} else {
if (m_registerCount <= 10) {
QTimer::singleShot(m_intervalTime,[this] {
registerTrayIcon();
});
}
}
}
/** /**
* @brief MainWindow::initTrayIcon * @brief MainWindow::initTrayIcon
*/ */
@ -285,17 +310,14 @@ void MainWindow::initTrayIcon()
iconTimer = new QTimer(this); iconTimer = new QTimer(this);
connect(iconTimer, &QTimer::timeout, this, &MainWindow::onSetTrayIconLoading); connect(iconTimer, &QTimer::timeout, this, &MainWindow::onSetTrayIconLoading);
m_trayIcon = new QSystemTrayIcon();
m_trayIconMenu = new QMenu(); m_trayIconMenu = new QMenu();
m_showMainwindowAction = new QAction(tr("Show MainWindow"),this); m_showMainwindowAction = new QAction(tr("Show MainWindow"),this);
m_showSettingsAction = new QAction(tr("Settings"),this); m_showSettingsAction = new QAction(tr("Settings"),this);
m_trayIcon->setToolTip(QString(tr("kylin-nm")));
m_showSettingsAction->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) ); m_showSettingsAction->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) );
// m_trayIconMenu->addAction(m_showMainwindowAction); // m_trayIconMenu->addAction(m_showMainwindowAction);
m_trayIconMenu->addAction(m_showSettingsAction); m_trayIconMenu->addAction(m_showSettingsAction);
m_trayIcon->setContextMenu(m_trayIconMenu); m_trayIcon->setContextMenu(m_trayIconMenu);
m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic"));
iconStatus = IconActiveType::LAN_CONNECTED; iconStatus = IconActiveType::LAN_CONNECTED;
onRefreshTrayIcon(); onRefreshTrayIcon();

View File

@ -124,6 +124,7 @@ private:
void paintWithTrans(); void paintWithTrans();
void initUI(); void initUI();
void initDbusConnnect(); void initDbusConnnect();
void registerTrayIcon();
void initTrayIcon(); void initTrayIcon();
void resetTrayIconTool(); void resetTrayIconTool();
void initWindowTheme(); void initWindowTheme();
@ -157,6 +158,8 @@ private:
QMenu * m_trayIconMenu = nullptr; QMenu * m_trayIconMenu = nullptr;
QAction * m_showMainwindowAction = nullptr; QAction * m_showMainwindowAction = nullptr;
QAction * m_showSettingsAction = nullptr; QAction * m_showSettingsAction = nullptr;
uint m_intervalTime = 100;
uint m_registerCount = 0;
bool m_lanIsLoading = false; bool m_lanIsLoading = false;
bool m_wlanIsLoading = false; bool m_wlanIsLoading = false;