Jun-26-2018, 01:19 PM
This should get you started. I suggest you edit the .ui file with Qt Designer.
Also you will likely need to read Qt documentation to progress with your project, for now these should be revelant:
https://doc.qt.io/qt-5/qfiledialog.html
https://doc.qt.io/qt-5/qtreewidget.html
https://doc.qt.io/qt-5/qtreewidgetitem.html
example.py
Also you will likely need to read Qt documentation to progress with your project, for now these should be revelant:
https://doc.qt.io/qt-5/qfiledialog.html
https://doc.qt.io/qt-5/qtreewidget.html
https://doc.qt.io/qt-5/qtreewidgetitem.html
example.py
#!/usr/bin/python3 import os import sys from PyQt5 import QtGui, QtWidgets, QtCore, uic LOCAL_DIR = os.path.dirname(os.path.realpath(__file__)) + '/' class Main(QtWidgets.QMainWindow): def __init__(self): super().__init__() self.ui = uic.loadUi(LOCAL_DIR + '/gui_main.ui', self) self.setWindowTitle("Window tite example") self.statusBar().showMessage("Current file: " + self.browsePrompt()) self.setTreeData() self.show() def browsePrompt(self): browser = QtWidgets.QFileDialog() browser.setNameFilter("Spreadsheets (*.xls *.xlsx)") if browser.exec_(): return(browser.selectedFiles()[0]) return "None" def setTreeData(self): item = QtWidgets.QTreeWidgetItem() item.setText(0, "data 1") item.setText(1, "data 2") subItem = QtWidgets.QTreeWidgetItem() subItem.setText(0, "subdata 1") subItem.setText(1, "subdata 2") item.addChild(subItem) self.ui.treeWidget.addTopLevelItem(item) self.ui.treeWidget.expandAll() def main(): global app app = QtWidgets.QApplication([]) main = Main() sys.exit(app.exec_()) if __name__ == '__main__': main()gui_main.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"> <layout class="QGridLayout" name="gridLayout"> <item row="0" column="0"> <widget class="QTreeWidget" name="treeWidget"> <column> <property name="text"> <string>Column 1</string> </property> </column> <column> <property name="text"> <string>Column 2</string> </property> </column> </widget> </item> </layout> </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="QStatusBar" name="statusbar"/> </widget> <resources/> <connections/> </ui>