Qt - QWidget 到底是什么
在《使用 Qt 4 进行 C++ GUI 编程》一书中,第一章的示例中提到,QWidget
充当应用程序的主窗口。
并且,在Qt参考文档
上:http://doc。 qt.io/qt-4.8/qwidget.html 有很多关于 QWidget 的信息。
但是,底线是什么? QWidget主要是做什么的?我什么时候应该考虑这个问题?
In the C++ GUI Programming with Qt 4
book, it mentions in an example in the first chapter that QWidget
serves as the application's main window.
And, on the Qt Reference Documentation
: http://doc.qt.io/qt-4.8/qwidget.html there is plenty of information about QWidget.
But, what is the baseline? What does QWidget mainly do? When should I think about it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一种思考方式是,任何知道如何在屏幕上显示自身的对象都是 QWidget(特别是 QWidget 的某个子类)。
有一些像 QPicture 这样的对象代表图像,但是 QPicture 本身不知道如何将自己放在屏幕上。例如,您通常需要将它与 QLabel(这是一种 QWidget)结合使用。
One way to think about it is any object that knows how to display itself on the screen is a QWidget (in particular, some subclass of QWidget).
There are some objects like QPicture that represent an image, but a QPicture by itself doesn't know how to put itself on the screen. You usually need to use it in combination with a QLabel for instance (which is a kind of QWidget).
它是窗口对象的抽象。每个可见/不可见的 Qt 窗口相关对象都继承自 QWidget。
就以车辆为例,它是汽车、卡车和其他东西的抽象。
It is an abstract of window objects. Every visible/invisible Qt window-related object inherits from QWidget.
Just consider a vehicle, it is the abstract of cars, trucks and other stuffs.
Widget 是 X11 的说法,指的是比其他系统所谓的控件更通用的东西。小部件可以是按钮、列表视图、窗口等......
顺便说一句,它据说来自Window Gadget。
Widget is X11 parlance for something a bit more generic that what other systems call a control. A widget can be a pushbutton, a listview, a window, etc...
And BTW, it supposedly comes from Window Gadget.
在像 X11 这样的窗口系统中,顶级窗口和小部件之间没有区别。所有窗口都称为“窗口”,并且所有窗口都有父窗口和子窗口(根窗口除外,根窗口通常是绘制桌面壁纸的窗口)。因此,小部件可以是顶级窗口(即根窗口的子窗口)或任何其他窗口是有道理的。
In windowing systems like X11, there is no difference between a toplevel window and a widget. All are called "windows", and all of them have a parent and children (except the root window, which is usually what the desktop wallpaper is drawn on). So it makes sense that a widget can either be a toplevel window (i.e. a child of the root window) or any other window.