Skip to content

Instantly share code, notes, and snippets.

@antonl
Last active August 29, 2015 14:24
Show Gist options
  • Save antonl/91691ced3ba514d53cd9 to your computer and use it in GitHub Desktop.
Save antonl/91691ced3ba514d53cd9 to your computer and use it in GitHub Desktop.
PyQt4 Ui Example
from __future__ import print_function, unicode_literals
import sys
from PyQt4 import QtGui, QtCore
from main_ui import Ui_MainWindow
import subprocess
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.setupUi(self)
self.setup_signals()
def setup_signals(self):
self.pbSimulate.clicked.connect(self.on_simulate)
def closeEvent(self, event):
event.accept()
def on_simulate(self):
print('Simulate clicked!')
try:
subprocess.check_call(['cat', 'main_ui.py'])
except subprocess.CalledProcessError as e:
print('Got return code {:d}'.format(e.returncode))
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>879</width>
<height>585</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Tab 1</string>
</attribute>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>30</x>
<y>40</y>
<width>261</width>
<height>191</height>
</rect>
</property>
<property name="title">
<string>GroupBox</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QCheckBox" name="checkBox_8">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="cb_Param1">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="checkBox_3">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="checkBox_7">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QCheckBox" name="checkBox_4">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="checkBox_6">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkBox_5">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="checkBox_9">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QComboBox" name="comboBox">
<property name="geometry">
<rect>
<x>350</x>
<y>60</y>
<width>104</width>
<height>26</height>
</rect>
</property>
</widget>
<widget class="QSpinBox" name="spinBox">
<property name="geometry">
<rect>
<x>360</x>
<y>110</y>
<width>53</width>
<height>24</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pbSimulate">
<property name="geometry">
<rect>
<x>480</x>
<y>300</y>
<width>131</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Simulate</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>380</x>
<y>190</y>
<width>131</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>File select</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>300</x>
<y>200</y>
<width>56</width>
<height>13</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>500</x>
<y>40</y>
<width>133</width>
<height>81</height>
</rect>
</property>
<property name="title">
<string>GroupBox</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QRadioButton" name="radioButton">
<property name="text">
<string>RadioButton</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="radioButton_2">
<property name="text">
<string>RadioButton</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QGroupBox" name="groupBox_3">
<property name="geometry">
<rect>
<x>520</x>
<y>130</y>
<width>133</width>
<height>81</height>
</rect>
</property>
<property name="title">
<string>GroupBox</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QRadioButton" name="radioButton_3">
<property name="text">
<string>RadioButton</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="radioButton_4">
<property name="text">
<string>RadioButton</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Page</string>
</attribute>
<widget class="QSlider" name="horizontalSlider">
<property name="geometry">
<rect>
<x>100</x>
<y>60</y>
<width>160</width>
<height>22</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QGroupBox" name="groupBox_4">
<property name="geometry">
<rect>
<x>90</x>
<y>150</y>
<width>154</width>
<height>152</height>
</rect>
</property>
<property name="title">
<string>GroupBox</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QSlider" name="verticalSlider">
<property name="maximum">
<number>1000</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="pageStep">
<number>50</number>
</property>
<property name="value">
<number>25</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksAbove</enum>
</property>
<property name="tickInterval">
<number>100</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="verticalSlider_2">
<property name="maximum">
<number>10</number>
</property>
<property name="pageStep">
<number>5</number>
</property>
<property name="value">
<number>5</number>
</property>
<property name="tracking">
<bool>true</bool>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksAbove</enum>
</property>
<property name="tickInterval">
<number>2</number>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="tab_4">
<attribute name="title">
<string>Page</string>
</attribute>
</widget>
<widget class="QWidget" name="tab_5">
<attribute name="title">
<string>Page</string>
</attribute>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Tab 2</string>
</attribute>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>879</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment