gpt4 book ai didi

c++ - View 如何在幕后更新?

转载 作者:行者123 更新时间:2023-11-28 01:22:57 25 4
gpt4 key购买 nike

因此,例如,当我在 QLabel 上使用 setText() 时,Qt 会自动为我更新 View /gui 并显示新文本,但幕后发生了什么?在使用 setText() 等函数时,是否有自动调用的更新函数?

谢谢!!

最佳答案

您应该查看此 link 中的基本文档.

内部系统稍微复杂一点,但总的来说,它遵循观察者模式。这种机制允许检测用户 Action 或改变状态,并响应这个 Action 。

低级交互,如刷新屏幕,是通过 Event System 实现的

In Qt, events are objects, derived from the abstract QEvent class, that represent things that have happened either within an application or as a result of outside activity that the application needs to know about. Events can be received and handled by any instance of a QObject subclass, but they are especially relevant to widgets. This document describes how events are delivered and handled in a typical application.

所以,关于显示过程,有一个专门的事件。 QWidget 对象处理/订阅 PaintEvent,参见 QWidget::paintEvent .

This event handler can be reimplemented in a subclass to receive paint events passed in event. A paint event is a request to repaint all or part of a widget.

当您调用 QLineEdit::setText() 时,将在下次触发显示事件时根据操作系统配置、刷新率等重新绘制小部件。

对于高级交互,Qt 使用基于 signal/slot 的类似模式机制:

Observer pattern is used everywhere in GUI applications and often leads to some boilerplate code. Qt was created with the idea of removing this boilerplate code and providing a nice and clean syntax, and the signal and slots mechanism is the answer.

关于c++ - View 如何在幕后更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55258746/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com