日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

QT5 获取窗口、系统屏幕大小尺寸信息,Qt 获取控件位置坐标,屏幕坐标,相对父窗体坐标

發(fā)布時間:2025/3/11 windows 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 QT5 获取窗口、系统屏幕大小尺寸信息,Qt 获取控件位置坐标,屏幕坐标,相对父窗体坐标 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、QT5 獲取窗口大小尺寸信息
QT窗口尺寸,窗口大小和大小改變引起的事件 QResizeEvent。

//窗口左上角的位置(含邊框)qDebug() << this->frameGeometry().x() << this->frameGeometry().y() << ;//1qDebug() << this->x() << this->y();//2qDebug() << this->pos().x() << this->pos().y();//3//窗口的寬度和高度(含邊框)qDebug() << this->frameGeometry().width() << this->frameGeometry().height();//窗口左上角的位置(不含邊框)qDebug() << this->geometry().x() << this->geometry().y();//窗口的寬度和高度(不含邊框)qDebug() << this->geometry().width() << this->geometry().height();//1qDebug() << this->width() << this->height();//2qDebug() << this->rect().width() << this->rect().height();//3qDebug() << this->size().width() << this->size().height();//4

二、QT獲取系統(tǒng)屏幕大小
QDesktopWidget 提供了詳細的位置信息,其能夠自動返回窗口在用戶窗口的位置和應用程序窗口的位置,

QDesktopWidget* pDesktopWidget = QApplication::desktop();//獲取可用桌面大小QRect deskRect = QApplication::desktop()->availableGeometry();//獲取主屏幕分辨率QRect screenRect = QApplication::desktop()->screenGeometry();//獲取屏幕數(shù)量int nScreenCount = QApplication::desktop()->screenCount();

Qt5開始,QDesktopWidget官方不建議使用,改為QScreen。

#include<QScreen> #include<QRect>QList<QScreen *> list_screen = QGuiApplication::screens(); //多顯示器 QRect rect = list_screen.at(0)->geometry(); desktop_width = rect.width(); desktop_height = rect.height(); qDebug() << desktop_width <<desktop_height;

三、設置窗體大小

void setGeometry(int x, int y, int w, int h)void setGeometry(const QRect &)void resize(int w, int h)void resize(const QSize &)

四、Qt 獲取控件位置坐標,屏幕坐標,相對父窗體坐標

QPoint QMouseEvent::pos()

這個只是返回相對這個widget(重載了QMouseEvent的widget)的位置。

QPoint QMouseEvent::globalPos()

窗口坐標,這個是返回鼠標的全局坐標

QPoint QCursor::pos() [static]

返回相對顯示器的全局坐標

QPoint QWidget::mapToGlobal(const QPoint & pos) const

將窗口坐標轉(zhuǎn)換成顯示器坐標

QPoint QWidget::mapFromGlobal(const QPoint & pos) const

將顯示器坐標轉(zhuǎn)換成窗口坐標

QPoint QWidget::mapToParent(const QPoint & pos) const

將窗口坐標獲得的pos轉(zhuǎn)換成父類widget的坐標

QPoint QWidget::mapFromParent(const QPoint & pos) const

將父類窗口坐標轉(zhuǎn)換成當前窗口坐標

QPoint QWidget::mapTo(const QWidget * parent, const QPoint &pos) const

將當前窗口坐標轉(zhuǎn)換成指定parent坐標。

QWidget::pos() : QPoint

這個屬性獲得的是當前目前控件在父窗口中的位置,

const QPointF &QMouseEvent::screenPos() const

Returns the position of the mouse cursor asa QPointF, relative to the screen that received the event.
和QPoint QMouseEvent::globalPos() 值相同,但是類型更高精度的QPointF
This function was introduced in Qt 5.0.

QCursor::pos() == QMouseEvent::globalPos()

獲取全局坐標

QMouseEvent::globalPos() == ui.posBtn->mapToGlobal(ui.posBtn->pos());

將鼠標的坐標轉(zhuǎn)換成全局坐標。

ui.posBtn->mapFromGlobal(QCursor::pos());

將全局坐標(鼠標當前坐標,QCursor::pos())直接轉(zhuǎn)換成當前窗口相對坐標

總結

以上是生活随笔為你收集整理的QT5 获取窗口、系统屏幕大小尺寸信息,Qt 获取控件位置坐标,屏幕坐标,相对父窗体坐标的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。