I am learning Qt and how to create GUIs with python. I managed to create my own Qt files and fill it with buttons and other simple things, but now I found this amazing attitude indicator
This ai.py file contains an attitude widget that I would like to import in my own GUI. So I designed my .ui file with an empty widget named "viz_widget", then I wrote this python file
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore, QtGui, uic
from ai import AttitudeIndicator
qtCreatorFile1 = "mainwindow.ui" # Enter file here.
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile1)
class OperatorGUI(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(OperatorGUI, self).__init__(parent)
QtGui.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.viz_widget = AttitudeIndicator()
self.viz_widget.setPitch(10)
self.viz_widget.setRoll(20)
self.viz_widget.setHover(500/10.)
self.viz_widget.setBaro(500/10.)
self.viz_widget.update()
# Key press functions
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Q: #Q: close the window
print "pressed Q: exit by keyboard"
self.close()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = OperatorGUI()
window.show()
sys.exit(app.exec_())
The GUI is launched, there aren't any errors, but I can not display the attitude widget into my GUI. Is it possible to import the widget? What is my error?
Thank you in advance
EDIT: this is the file maiwindow.ui
<?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>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QWidget" name="viz_widget" native="true">
<property name="geometry">
<rect>
<x>50</x>
<y>40</y>
<width>671</width>
<height>441</height>
</rect>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>