Qt入門1---widget、mainwindow和Dialog區別


摘要: 看了一個月的Qt,居然沒有理清Qt中

------------------------------------

1.QMainWindow

A main window provides a framework for building an application's user interface. Qt has QMainWindow and its related classes for main window management. QMainWindow has its own layout to which you can addQToolBars, QDockWidgets, a QMenuBar, and a QStatusBar. The layout has a center area that can be occupied by any kind of widget. You can see an image of the layout below.

2.QDialog

 

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. QDialogs can provide a return value, and they can have default buttons. QDialogs can also have a QSizeGrip in their lower-right corner, using setSizeGripEnabled().

 

Note that 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.

 

重要的看.............

QDialog繼承自QWidget。
那么,看一下QDialog都新增了哪些功能。如果你需要這些新增的功能,那么考慮使用QDialog。
Qt文檔中有這樣一段介紹文字:
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. QDialogs can provide a return value, and they can have default buttons. 
從這段話可以看出,QDialog通常作為一個頂層窗口出現,允許用戶進行一些選擇,並返回用戶選擇的結果(比如:在一個配置對話框里,用戶操作完后是按下了“確定”、“應用”或“取消”)。然后應用程序就可以根據用戶剛才的選擇決定下一步做什么(比如:如果用戶剛才按下了“確定”,那么就保存用戶在配置對話框中進行的更改等)。

由於QDialog通常作為頂層窗口,所以在使用諸如QStackedLayout這樣的布局類時,一般上使用QWidget這樣“原始”的窗體,然后把它添加到Stacked Layout中作為其中的一個Page。

QWidget中有個方法叫SetLayout,QDialog繼承了它。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM