天天看點

QT Desinger設計窗體應用程式架構前言 系統軟體 QT Designer Using QT Designer 示例

qt desinger這個工具讓我們可以想c#一樣通過拖動元件來開發gui應用程式。對于新手或靈活開發而言都是一大利器,但是如果希望深入的學習qt底層代碼實作的話,這當然不是一個好的選擇。

系統 

win 10

軟體 

pycharm 5

python 3.4.3

pyqt 4

摘要: 

qt designer is the qt tool for designing and building graphical user interfaces (guis) with qt widgets. you can compose and customize your windows or dialogs in a what-you-see-is-what-you-get (wysiwyg) manner, and test them using different styles and resolutions. 

widgets and forms created with qt designer integrate seamlessly with programmed code, using qt’s signals and slots mechanism, so that you can easily assign behavior to graphical elements. all properties set in qt designer can be changed dynamically within the code. furthermore, features like widget promotion and custom plugins allow you to use your own components with qt designer. 

qt designer 是建構和設計圖形使用者界面(gui)的qt工具。可以以所見即所得(what-you-see-is-what-you-get)的方式來組合和定制你的視窗或者對話框,并且可以使用不同的風格和解決方案來測試。 

使用qt designer建立的部件和表單,你可以無縫的将這些部件的信号和槽內建到程式代碼中,是以你能夠很容易的去指定圖形元件的動作。在qt designer中設定的屬性值在代碼中可以動态的更改,而且qt designer允許你使用自己擁有的部件和自定義插件。

使用qt designer的幾個步驟: 

1)建立窗體并在窗體中放置各種控件。 

2)對窗體進行布局設計。 

3)設定各控件的标簽順序。 

4)建立信号和槽。 

5)連接配接信号和槽。

QT Desinger設計窗體應用程式架構前言 系統軟體 QT Designer Using QT Designer 示例

啟動qt designer後,提供了5種表單樣式 

1)底部帶”确定”,”取消”按鈕的對話框窗體。 

2)右側帶”确定”,”取消”按鈕的對話框窗體。 

3)不帶按鈕的對話框窗體。 

4)main window類型窗體。 

5)通用窗體。

QT Desinger設計窗體應用程式架構前言 系統軟體 QT Designer Using QT Designer 示例

qt designer的控件欄 

左邊是控件欄,提供了很多控件類,可以像visual studio那樣直接将控件拖放qwidget中看到效果,ctrl+r可以預覽效果。 

QT Desinger設計窗體應用程式架構前言 系統軟體 QT Designer Using QT Designer 示例

qt designer widget box 中的layouts控件提供了四種布局方法: 

vertical layout 縱向布局 

horizontal layout 橫向布局 

grid layout 栅格布局 

form layout 在窗體布局中布局

QT Desinger設計窗體應用程式架構前言 系統軟體 QT Designer Using QT Designer 示例

右邊是對視窗及控件的調整、設定、動作 、添加資源(列如:圖檔)。還可以直接編輯qt的信号槽(signal和slot)。 

通過信号槽機制,qt使對象間的通信變得非常簡單,example: 

對象a聲明信号(signal),對象b實作與a參數相比對的槽(slot),通過調用connect()進行連接配接,合适的時機對象a使用emit把帶上參數的信号發射出去,對象b的槽會就接收到響應,并做出動作。 

信号與槽作為qt的核心機制,在qt程式中廣泛應用,以後再專門介紹。

QT Desinger設計窗體應用程式架構前言 系統軟體 QT Designer Using QT Designer 示例

mainwindows預設添加了菜單欄(menubar)、工具欄和狀态欄(statusbar)等 

QT Desinger設計窗體應用程式架構前言 系統軟體 QT Designer Using QT Designer 示例
QT Desinger設計窗體應用程式架構前言 系統軟體 QT Designer Using QT Designer 示例

在設計窗體架構的時候需要注意層次之間的關系,這個可以在對象檢視器中得到展現 

QT Desinger設計窗體應用程式架構前言 系統軟體 QT Designer Using QT Designer 示例

還可以在屬性編輯器中對每一個部件的屬性進行設計 

QT Desinger設計窗體應用程式架構前言 系統軟體 QT Designer Using QT Designer 示例

預設儲存到pycharm目前項目的workspace中。 

QT Desinger設計窗體應用程式架構前言 系統軟體 QT Designer Using QT Designer 示例

1

command line pyuic4: 

the pyuic4 utility is a command line interface to the uic module. the command has the following syntax:

the full set of command line options is: 

-h, –help 

–version 

-o <code>&lt;file&gt;</code>, –output <code>&lt;file&gt;</code> 指定轉換成.py檔案的檔案名 

-p, –preview 預覽 

-w, –pyqt3-wrapper 封裝器,相容pyqt3 

-x, –execute the generated python code includes a small amount of additional code that creates and displays the gui when it is executes as a standalone application. 

–from-imports resource modules are imported using from . import rather than a simple import. 

–resource-suffix <code>&lt;suffix&gt;</code> the suffix <code>&lt;suffix&gt;</code> is appended to the basename of any resource file specified in the .ui file to create the name of the python module generated from the resource file by pyrcc4. the default is _rc. for example if the .ui file specified a resource file called foo.qrc then the corresponding python module is foo_rc. 當使用資源的時候需要注意

QT Desinger設計窗體應用程式架構前言 系統軟體 QT Designer Using QT Designer 示例
QT Desinger設計窗體應用程式架構前言 系統軟體 QT Designer Using QT Designer 示例

ok! 在獲得了.py檔案之後你就可以繼續之後的邏輯層程式的編寫了。

done

轉載:http://blog.csdn.net/jmilk/article/details/50734882