qt中widget与dialog如何选择?

如题所述

第1个回答  2022-12-11
QDialog继承自QWidget。\x0d\x0a那么,看一下QDialog都新增了哪些功能。如果你需要这些新增的功能,那么考虑使用QDialog。\x0d\x0aQt文档中有这样一段介绍文字:\x0d\x0aA 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. QDialogs can provide a return value, and they can have default buttons. \x0d\x0a从这段话可以看出,QDialog通常作为一个顶层窗口出现,允许用户进行一些选择,并返回用户选择的结果(比如:在一个配置对话框里,用户操作完后是按下了“确定”、“应用”或“取消”)。然后应用程序就可以根据用户刚才的选择决定下一步做什么(比如:如果用户刚才按下了“确定”,那么就保存用户在配置对话框中进行的更改等)。\x0d\x0a\x0d\x0a由于QDialog通常作为顶层窗口,所以在使用诸如QStackedLayout这样的布局类时,一般上使用QWidget这样“原始”的窗体,然后把它添加到Stacked Layout中作为其中的一个Page。\x0d\x0a\x0d\x0aQWidget中有个方法叫SetLayout,QDialog继承了它。
相似回答