I am trying to get this: a link! in my pyqt program but it isn't working I have tryed a lot and resolved a lot of errors but with this one I don't know what to do. I am just tarting with pyqt and I do not have a lot of experience with python. And is there a way to automaticly start :(def load_project_structure) when the program starts insteat of using the temp testing button?
PyQt code:
<?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>1483</width>
<height>638</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="opnemen">
<property name="geometry">
<rect>
<x>470</x>
<y>10</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Opnemen</string>
</property>
</widget>
<widget class="QPushButton" name="import_2">
<property name="geometry">
<rect>
<x>470</x>
<y>40</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Inport</string>
</property>
</widget>
<widget class="QTreeWidget" name="FileStuckture">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>451</width>
<height>561</height>
</rect>
</property>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
<widget class="QPushButton" name="testing">
<property name="geometry">
<rect>
<x>470</x>
<y>80</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>testing</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1483</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
Python code:
import os, sys
import sounddevice as sd
from scipy.io.wavfile import write
from PyQt5 import QtCore, QtGui, QtWidgets, uic
from PyQt5.QtWidgets import QTreeWidgetItem
from PyQt5.QtGui import QIcon
from pathlib import Path
qtcreator_file = "mainwindow.ui" # Enter file here.
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtcreator_file)
class MyWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.testing.clicked.connect(self.load_project_structure)
startpath = Path("D:/DemoGIPhoofdmap")
def load_project_structure(startpath, FileStuckture):
startpathh = Path("D:/DemoGIPhoofdmap/")
for element in os.listdir(startpathh):
path_info = startpathh / element
parent_itm = QTreeWidgetItem(FileStuckture, [os.path.basename(element)])
if os.path.isdir(path_info):
load_project_structure(path_info, parent_itm)
parent_itm.setIcon(0, QIcon('assets/folder.ico'))
else:
parent_itm.setIcon(0, QIcon('assets/file.ico'))
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())
Error message on line 24:
parent_itm = QTreeWidgetItem(FileStuckture, [os.path.basename(element)])
TypeError: arguments did not match any overloaded call:
QTreeWidgetItem(type: int = QTreeWidgetItem.Type): too many arguments
QTreeWidgetItem(Iterable[str], type: int = QTreeWidgetItem.Type): argument 1 has unexpected type 'bool'
QTreeWidgetItem(QTreeWidget, type: int = QTreeWidgetItem.Type): argument 1 has unexpected type 'bool'
QTreeWidgetItem(QTreeWidget, Iterable[str], type: int = QTreeWidgetItem.Type): argument 1 has unexpected type 'bool'
QTreeWidgetItem(QTreeWidget, QTreeWidgetItem, type: int = QTreeWidgetItem.Type): argument 1 has unexpected type 'bool'
QTreeWidgetItem(QTreeWidgetItem, type: int = QTreeWidgetItem.Type): argument 1 has unexpected type 'bool'
QTreeWidgetItem(QTreeWidgetItem, Iterable[str], type: int = QTreeWidgetItem.Type): argument 1 has unexpected type 'bool'
QTreeWidgetItem(QTreeWidgetItem, QTreeWidgetItem, type: int = QTreeWidgetItem.Type): argument 1 has unexpected type 'bool'
QTreeWidgetItem(QTreeWidgetItem): argument 1 has unexpected type 'bool'