增加UI针对屏幕尺寸变化时的自动更新位置操作

This commit is contained in:
iaom 2023-03-23 10:00:43 +08:00
parent ea3913cb5b
commit 87f4170a5e
2 changed files with 8 additions and 30 deletions

View File

@ -81,7 +81,6 @@ MainWindow::MainWindow(QWidget *parent) :
installEventFilter(this); installEventFilter(this);
initConnections(); initConnections();
// connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this,[&](WId activeWindowId){ // connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this,[&](WId activeWindowId){
// qDebug() << "activeWindowChanged!!!" << activeWindowId; // qDebug() << "activeWindowChanged!!!" << activeWindowId;
// if (activeWindowId != this->winId()) { // if (activeWindowId != this->winId()) {
@ -134,8 +133,7 @@ void MainWindow::initUi() {
void MainWindow::initConnections() void MainWindow::initConnections()
{ {
connect(m_sys_tray_icon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivatedSlot); connect(m_sys_tray_icon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivatedSlot);
connect(QApplication::primaryScreen(), &QScreen::geometryChanged, this, &MainWindow::monitorResolutionChange); connect(QApplication::primaryScreen(), &QScreen::geometryChanged, this, &MainWindow::ScreenGeometryChanged);
connect(qApp, &QApplication::primaryScreenChanged, this, &MainWindow::primaryScreenChangedSlot);
connect(m_askDialog, &CreateIndexAskDialog::closed, this, [ = ]() { connect(m_askDialog, &CreateIndexAskDialog::closed, this, [ = ]() {
m_isAskDialogVisible = false; m_isAskDialogVisible = false;
}); });
@ -258,21 +256,11 @@ void MainWindow::tryHide()
this->tryHideMainwindow(); this->tryHideMainwindow();
} }
/** void MainWindow::ScreenGeometryChanged(QRect rect) {
* @brief monitorResolutionChange
* @param rect
*/
void MainWindow::monitorResolutionChange(QRect rect) {
Q_UNUSED(rect); Q_UNUSED(rect);
} if(this->isVisible()) {
centerToScreen(this);
/** }
* @brief primaryScreenChangedSlot
* @param screen
*/
void MainWindow::primaryScreenChangedSlot(QScreen *screen) {
Q_UNUSED(screen);
} }
/** /**
@ -336,12 +324,10 @@ void MainWindow::centerToScreen(QWidget* widget) {
if(!widget) if(!widget)
return; return;
KWindowSystem::setState(this->winId(),NET::SkipTaskbar | NET::SkipPager); KWindowSystem::setState(this->winId(),NET::SkipTaskbar | NET::SkipPager);
QDesktopWidget* m = QApplication::desktop(); QRect desk_rect = qApp->screenAt(QCursor::pos())->geometry();
QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos()));
int desk_x = desk_rect.width(); int desk_x = desk_rect.width();
int desk_y = desk_rect.height(); int desk_y = desk_rect.height();
int x = widget->width(); int x = widget->width();
int y = widget->height();
widget->show(); widget->show();
kdk::WindowManager::setGeometry(this->windowHandle(),QRect(desk_x / 2 - x / 2 + desk_rect.left(), kdk::WindowManager::setGeometry(this->windowHandle(),QRect(desk_x / 2 - x / 2 + desk_rect.left(),
desk_y / 3 + desk_rect.top(), desk_y / 3 + desk_rect.top(),

View File

@ -87,16 +87,8 @@ public:
bool eventFilter(QObject *watched, QEvent *event) override; bool eventFilter(QObject *watched, QEvent *event) override;
public Q_SLOTS: public Q_SLOTS:
/**
* @brief Monitor screen resolution void ScreenGeometryChanged(QRect rect);
* @param rect: Screen resolution
*/
void monitorResolutionChange(QRect rect);
/**
* @brief Monitor primary screen changes
* @param screen: Primary screen
*/
void primaryScreenChangedSlot(QScreen *screen);
void bootOptionsFilter(QString opt); // 过滤终端命令 void bootOptionsFilter(QString opt); // 过滤终端命令
void clearSearchResult(); //清空搜索结果 void clearSearchResult(); //清空搜索结果
void trayIconActivatedSlot(QSystemTrayIcon::ActivationReason reason); void trayIconActivatedSlot(QSystemTrayIcon::ActivationReason reason);