Qt: QWidget,QDialog, 和 QMainwindow

QWidget

参考:Qt Help

Inherits: QObject and QPaintDevice

The QWidget class is the base class of all user interface objects.

A widget that is not embedded in a parent widget is called a window.

In Qt, QMainWindow and the various subclasses of QDialog are the most common window types.

Every widget’s constructor accepts one or two standard arguments:

  1. QWidget *parent = 0 is the parent of the new widget. If it is 0 (the default), the new widget will be a window. If not, it will be a child of parent, and be constrained by parent’s geometry (unless you specify Qt::Window as window flag).
  2. Qt::WindowFlags f = 0 (where available) sets the window flags; the default is suitable for almost all widgets, but to get, for example, a window without a window system frame, you must use special flags.

QDialog

Inherits: QWidget

The QDialog class is the base class of dialog windows.

A dialog window is a top-level window mostly used for short-term tasks and brief communications with the user.

QDialogs may be modal or modeless.

modal dialog: A modal dialog is a dialog that blocks input to other visible windows in the same application.

modeless dialog: A modeless dialog is a dialog that operates independently of other windows in the same application.

QDialogs can provide a return value, and they can have default buttons.

return value (modal dialogs): Modal dialogs are often used in situations where a return value is required, e.g. to indicate whether the user pressed OK or Cancel.

The function returns a DialogCode result.

default buttons: A dialog’s default button is the button that’s pressed when the user presses Enter (Return).

Esc key: If the user presses the Esc key in a dialog, QDialog::reject() will be called. This will cause the window to close: The close event cannot be ignored.

QDialog (and any other widget that has type Qt::Dialog) uses the parent widget slightly differently from other classes in Qt ???

A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent’s top-level widget (if it is not top-level itself).

It will also share the parent’s taskbar entry.

QMainwindow

Inherits: QWidget

The QMainWindow class provides a main application window.

QMainWindow has its own layout to which you can add QToolBars, QDockWidgets, a QMenuBar, and a QStatusBar.

The layout has a center area that can be occupied by any kind of widget.

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值