网站优化要怎么做才会做到最佳,暴雪国服回归消息今天最新,购物网站建设目标客户分析论文,深圳设计院有哪些标题栏自定义
参考博客 #xff1a; https://blog.csdn.net/goforwardtostep/article/details/53494800
多屏适配
MyTitleBar类抽象定义了自定义标题栏#xff0c;使用起来相对方便。但是在多屏情况下#xff0c;窗口初次显示只能在主屏幕上#xff0c;如果拖到其他屏幕…标题栏自定义
参考博客 https://blog.csdn.net/goforwardtostep/article/details/53494800
多屏适配
MyTitleBar类抽象定义了自定义标题栏使用起来相对方便。但是在多屏情况下窗口初次显示只能在主屏幕上如果拖到其他屏幕上最大化还会回到主屏。
处理方式如下 获取当前屏幕的索引 /* MyTitleBar 的 mouseMoveEvent 函数*/
void MyTitleBar::mouseMoveEvent(QMouseEvent *event) {if (_isPressed) {QPoint movePoint event-globalPos() - _startMovePos;QPoint widgetPos this-parentWidget()-pos();_startMovePos event-globalPos();this-parentWidget()-move(widgetPos.x() movePoint.x(), widgetPos.y() movePoint.y());// 每次移动后 获取当前屏幕的索引currentScreenIndex QApplication::desktop()-screenNumber(this-parentWidget);}return QWidget::mouseMoveEvent(event);
}根据索引获取屏幕大小信息QRect /*使用MyTitleBar的窗口*/
void MainPage::onButtonMaxClicked() {_titleBar-saveRestoreInfo(this-pos(),QSize(this-width(),this-height()));QRect desktopRect QApplication::desktop()-availableGeometry(_titleBar-getCurrentScreenIndex()); // availableGeometry(int) 传入索引值获取目标屏幕的QRectQRect factRect QRect(desktopRect.x()-3,desktopRect.y()-3, desktopRect.width()6,desktopRect.height()6);setGeometry(factRect);
}注意事项
QApplication::desktop()-screenNumber() 函数默认获取的是主屏幕的索引通过传入QWidget*参数获取当前窗口所在屏幕获取屏幕大小有两个函数 QApplication::desktop()-availableGeometry(no) QApplication::desktop()-screenGeometry(no)尽量使用 QApplication::desktop()-availableGeometry(no)availableGeometry函数获取的是可用屏幕大小除去任务栏availableGeometry 与 screenGeometry不传参数时获取的是主屏幕的大小不要在QWidget的showEvent中获取屏幕的索引此时获取的都是主屏幕在QWidget.show()之后可以获取到窗口所在的屏幕