How do you use dialog forms in Qt designer?
How d开发者_StackOverflow中文版o you create and access dialog forms in Qt designer?
At the risk of pointing out the blisteringly obvious...
Qt Designer -> File -> New -> Dialog [with buttons/without buttons] -> Create.
You then drag widgets from the Widget Box into the dialog. (View -> Widget Box if you can't see it.)
If you want auto-sizing support, you drag a Layout into the Dialog, then drag your Widgets into the layout.
Qt Designer -> File -> New
Click Create.
Can view code by Menu->Form->ViewCode
Generally, you create a dialog form the same way you do other widgets in Qt designer. That is to say, create a new widget, and fill it with the widgets you want. You'll need to create code files to manage how the dialog works, of course.
To show the dialog, you should create an instance of the widget and show it. Generally, a widget that has no parent will be shown as a separate window. Alternately, if your widget inherits from QDialog
, you can pass a parent but it will still show as a separate window.
Launching QtDesigner with QtCreator 3.6.1
QtCreator 3.6.1
Qt 5.6
OSX Yosemite 10.10.5
I installed Qt via:
qt-unified-mac-x64-2.0.2-2-online.dmg
The default installation directory was /Users/7stud/Qt
. I found QtCreator.app
at the top level of that directory.
I installed sip and then pyqt from source:
PyQt-gpl-5.5.1.tar.gz
as presented here: https://www.riverbankcomputing.com/software/pyqt/download5
To access QtDesigner:
Launch QtCreator, and from the menu bar (outside QtCreator), click on:
File>New File or Project
You will be presented with a
New File or Project
dialog window. In theFiles And Classes
section, selectQt
. In the middle pane, selectQtDesigner Form
. Then click on theChoose
button in the lower right corner.You will be presented with a
QtDesigner Form
dialog window. Then you can selectMain Window
orDialog with Buttons Bottom
, etc. Then click on theContinue
button in the lower right corner.In the
Location
dialog window, use a name like mainwindow1.ui, and for the path you might want to step aside and create a directory called forms, e.g.$ mkdir /Users/7stud/qt_projects/forms
, then enter that as the path.Enter any other details and click on
Done
. That will land you in QtCreator with the Design button selected (which means you are in QtDesigner), and you will be able to drag and drop widgets onto your window.To convert the
.ui
file to a.py
file that you can import into your python program:$ pyuic5 mainwindow1.ui -o mainwindow1.py
-o => output file (default is stdout)
That command converts the .ui file
mainwindow1.ui
to a .py file namedmainwindow1.py
.
精彩评论