Python Forum
[PyQt] Help with PyQt5
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Help with PyQt5
#2
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
#!/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>
Reply


Messages In This Thread
Help with PyQt5 - by PVfan - May-23-2018, 01:59 PM
RE: Help with PyQt5 - by Alfalfa - Jun-26-2018, 01:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 2,857 Apr-06-2019, 11:15 PM
Last Post: ZenWoR

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020