当前位置: 首页 > news >正文

Qt之Gui

组件依赖关系

在这里插入图片描述

应用

QGuiApplication
QApplication
QCoreApplication

QApplication:widget对应的应用
QGuiApplication :gui对应的应用
QCoreApplication :无gui对应的应用

widget

QWidget
QMainWindow
QWidgetWindow
QWindow
QPlatformIntegration
QPlatformWindow

QPlatformIntegration:平台抽象
QPlatformWindow :平台 抽象窗口

windows平台

QPlatformIntegration
QWindowsIntegration
QPlatformWindow
QWindowsBaseWindow
QWindowsWindow
QWindowsDesktopWindow
QWindowsForeignWindow
QWindowsContext

在QWindowsIntegration创建createPlatformWindow时,其先创建QWindowsWindowData::create

QWindowsWindowDataWindowCreationData::create(const QWindow *w, const WindowData &data, QString title) const
{WindowData result;result.flags = flags;const auto appinst = reinterpret_cast<HINSTANCE>(GetModuleHandle(nullptr));const QString windowClassName = QWindowsContext::instance()->registerWindowClass(w);const QScreen *screen{};const QRect rect = QPlatformWindow::initialGeometry(w, data.geometry,defaultWindowWidth, defaultWindowHeight,&screen);if (title.isEmpty() && (result.flags & Qt::WindowTitleHint))title = topLevel ? qAppName() : w->objectName();const auto *titleUtf16 = reinterpret_cast<const wchar_t *>(title.utf16());const auto *classNameUtf16 = reinterpret_cast<const wchar_t *>(windowClassName.utf16());// Capture events before CreateWindowEx() returns. The context is cleared in// the QWindowsWindow constructor.const QWindowCreationContextPtr context(new QWindowCreationContext(w, screen, data.geometry,rect, data.customMargins,style, exStyle));QWindowsContext::instance()->setWindowCreationContext(context);const bool hasFrame = (style & (WS_DLGFRAME | WS_THICKFRAME));QMargins invMargins = topLevel && hasFrame && QWindowsGeometryHint::positionIncludesFrame(w)? invisibleMargins(QPoint(context->frameX, context->frameY)) : QMargins();qCDebug(lcQpaWindows).nospace()<< "CreateWindowEx: " << w << " class=" << windowClassName << " title=" << title<< '\n' << *this << "\nrequested: " << rect << ": "<< context->frameWidth << 'x' <<  context->frameHeight<< '+' << context->frameX << '+' << context->frameY<< " custom margins: " << context->customMargins<< " invisible margins: " << invMargins;QPoint pos = calcPosition(w, context, invMargins);// Mirror the position when creating on a parent in RTL mode, ditto for the obtained geometry.int mirrorParentWidth = 0;if (!w->isTopLevel() && QWindowsBaseWindow::isRtlLayout(parentHandle)) {RECT rect;GetClientRect(parentHandle, &rect);mirrorParentWidth = rect.right;}if (mirrorParentWidth != 0 && pos.x() != CW_USEDEFAULT && context->frameWidth != CW_USEDEFAULT)pos.setX(mirrorParentWidth - context->frameWidth - pos.x());result.hwnd = CreateWindowEx(exStyle, classNameUtf16, titleUtf16,style,pos.x(), pos.y(),context->frameWidth, context->frameHeight,parentHandle, nullptr, appinst, nullptr);qCDebug(lcQpaWindows).nospace()<< "CreateWindowEx: returns " << w << ' ' << result.hwnd << " obtained geometry: "<< context->obtainedPos << context->obtainedSize << ' ' << context->margins;if (!result.hwnd) {qErrnoWarning("%s: CreateWindowEx failed", __FUNCTION__);return result;}if (mirrorParentWidth != 0) {context->obtainedPos.setX(mirrorParentWidth - context->obtainedSize.width()-  context->obtainedPos.x());}QRect obtainedGeometry(context->obtainedPos, context->obtainedSize);result.geometry = obtainedGeometry;result.fullFrameMargins = context->margins;result.embedded = embedded;result.hasFrame = hasFrame;result.customMargins = context->customMargins;return result;
}

内部会先注册registerWindowClass,设置窗口的处理函数registerWindowClass(cname, qWindowsWndProc, style, GetSysColorBrush(COLOR_WINDOW), icon);
qWindowsWndProc处理函数主要是调用 QWindowsContext的windowsProc

QString QWindowsContext::registerWindowClass(QString cname,WNDPROC proc,unsigned style,HBRUSH brush,bool icon)
{// since multiple Qt versions can be used in one process// each one has to have window class names with a unique name// The first instance gets the unmodified name; if the class// has already been registered by another instance of Qt then// add a UUID. The check needs to be performed for each name// in case new message windows are added (QTBUG-81347).const auto appInstance = static_cast<HINSTANCE>(GetModuleHandle(nullptr));WNDCLASS wcinfo;const bool classExists = GetClassInfo(appInstance, reinterpret_cast<LPCWSTR>(cname.utf16()), &wcinfo) == TRUE&& wcinfo.lpfnWndProc != proc;if (classExists)cname += QUuid::createUuid().toString();if (d->m_registeredWindowClassNames.contains(cname))        // already registered in our listreturn cname;WNDCLASSEX wc;wc.cbSize       = sizeof(WNDCLASSEX);wc.style        = style;wc.lpfnWndProc  = proc;wc.cbClsExtra   = 0;wc.cbWndExtra   = 0;wc.hInstance    = appInstance;wc.hCursor      = nullptr;wc.hbrBackground = brush;if (icon) {wc.hIcon = static_cast<HICON>(LoadImage(appInstance, L"IDI_ICON1", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE));if (wc.hIcon) {int sw = GetSystemMetrics(SM_CXSMICON);int sh = GetSystemMetrics(SM_CYSMICON);wc.hIconSm = static_cast<HICON>(LoadImage(appInstance, L"IDI_ICON1", IMAGE_ICON, sw, sh, 0));} else {wc.hIcon = static_cast<HICON>(LoadImage(nullptr, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED));wc.hIconSm = nullptr;}} else {wc.hIcon    = nullptr;wc.hIconSm  = nullptr;}wc.lpszMenuName  = nullptr;wc.lpszClassName = reinterpret_cast<LPCWSTR>(cname.utf16());ATOM atom = RegisterClassEx(&wc);if (!atom)qErrnoWarning("QApplication::regClass: Registering window class '%s' failed.",qPrintable(cname));d->m_registeredWindowClassNames.insert(cname);qCDebug(lcQpaWindows).nospace() << __FUNCTION__ << ' ' << cname<< " style=0x" << Qt::hex << style << Qt::dec<< " brush=" << brush << " icon=" << icon << " atom=" << atom;return cname;
}
http://www.lryc.cn/news/415177.html

相关文章:

  • Linux操作系统之进程信号
  • 科普文:微服务之Spring Cloud Alibaba消息队列组件RocketMQ工作原理
  • 黑马头条vue2.0项目实战(五)——首页—频道编辑
  • Java:基础语法
  • 安装bedtools详细步骤和详细介绍bedtools用法
  • 21 - grace数据处理 - 补充 - 泄露误差改正 - Slepian局部谱分析法(一) - slepian分析法理论理解
  • WLAN国家码与信道顺从表
  • 行为型设计模式1:状态/策略/命令
  • 【知识专栏丨python数分实战】天猫订单数据分析及可视化|taobao天猫订单接口
  • [kimi笔记]为什么csc.exe不可以双击运行
  • 护眼大路灯哪个牌子好?2024学生护眼大路灯推荐
  • Vue项目中手搓滑动校验模块-demo
  • Socket如何实现客户端和服务器间的通信
  • 基于Spring boot + Vue的校园论坛
  • RabbitMQ高级特性 - 生产者消息确认机制
  • webpack的loader机制
  • (STM32笔记)十一、通过EXTI外部中断实现 按键控制LED
  • 假如家里太大了,wifi连不上了怎么办
  • elementPlus 设置el-input文本域固定高度和禁止下拉
  • (转)领导人必过的三道关
  • 速盾:cdn可以定时刷新缓存吗?
  • 代码随想录算法训练营第二十九天| 62.不同路径、63. 不同路径 II
  • Go+Redis零基础到用户管理系统API实战_20240730 课程笔记
  • ScreenAgent:基于LVLM的计算机控制智能体
  • 谷粒商城实战笔记-129-商城业务-商品上架-nested数据类型场景
  • axios请求响应拦截器
  • Python 中单例模式实现的几种方式
  • mysql数据库触发器同步数据
  • Prometheus-v2.45.0+Grafana+邮件告警
  • LeetCode——572. 另一颗树的子树