获取屏幕分辨率大小
以往获取屏幕分辨率的方法是用,但是QT5之后淘汰了,需要用QGuiApplication这个类来操作了
QDesktopWidget* desktopWidget = QApplication::desktop();//获取可用桌面大小
QRect deskRect = desktopWidget->availableGeometry();//获取设备屏幕大小
QRect screenRect = desktopWidget->screenGeometry();
新的方法如下
#include <QGuiApplication>
#include<QScreen>
QScreen *screen=QGuiApplication::primaryScreen ();//获取主屏幕
QRect mm=screen->availableGeometry() ;//返回屏幕可用几何图形大小
int screen_width = mm.width();//屏幕宽度
int screen_height = mm.height();//屏幕高度
QList<QScreen *> list_screen = QGuiApplication::screens();// 获取多显示器,通过list存储当前主机所有显示器
QRect rect = list_screen.at(0)->geometry();//获取第一个屏幕
int desktop_width = rect.width();//屏幕宽度
int desktop_height = rect.height();//屏幕高度
QPoint f = QPoint(25, 25);
QScreen * scree = QGuiApplication::screenAt(f);//返回点所在的屏幕
QWidget窗口的部分显示有关的功能
QT中,GUI最终都继承自QWidget,所的调用update()都是基类QWidget的update()。
基础函数:
paintEvent(QPaintEvent*)函数是QWidget类中的虚函数,用于ui的绘制,会在多种情况下被其他函数自动调用,比如update()时
-
repaint(),被调用之后,立即执行重绘,因此repaint是最快的
-
update()跟repaint()比较,update则更加有优越性
void update(const QRect&);
void update(const QRegion&);
void repaint(int x, int y, int w, int h);
void repaint(const QRect &);
void repaint(const QRegion &);
void showMinimized();//缩放最小
void showMaximized();//缩放最大
void showFullScreen();//全屏显示
void showNormal();//正常显示
void show();//显示
void hide();//隐藏
bool close();//关闭
void raise();//显示窗体在最前面
void lower();//显示窗体在最后面