python - Adding items from a text file to QlistWidget in pyQt5 -
i've been working on code part of school project , don't seem getting anywhere. problem when try add text file qlistwidget program crashes. firstly want know if add files @ directory (each line in moviedir.txt
directory) qlistwidget, secondly i'm not sure if i'm using right widget or if should qlistview. how make selected item in listwidget shows details in text box (e.g. size of file).
i'm looking done on start if can please tell me the additems(self)
appreciated. i'm new using classes have been neglected taught in school.
i'm running pyqt5 on windows 7
# -*- coding: utf-8 -*- # form implementation generated reading ui file 'input.ui' # # created by: pyqt5 ui code generator 5.6 # # warning! changes made in file lost! pyqt5 import qtcore, qtgui, qtwidgets class ui_mainwindow(object): def setupui(self, mainwindow): mainwindow.setobjectname("mainwindow") mainwindow.resize(764, 500) mainwindow.setminimumsize(qtcore.qsize(764, 353)) mainwindow.setmaximumsize(qtcore.qsize(764, 500)) self.centralwidget = qtwidgets.qwidget(mainwindow) self.centralwidget.setobjectname("centralwidget") self.verticallayout = qtwidgets.qvboxlayout(self.centralwidget) self.verticallayout.setcontentsmargins(11, 11, 11, 11) self.verticallayout.setspacing(6) self.verticallayout.setobjectname("verticallayout") self.horizontallayout_2 = qtwidgets.qhboxlayout() self.horizontallayout_2.setcontentsmargins(11, 11, 11, 11) self.horizontallayout_2.setspacing(6) self.horizontallayout_2.setobjectname("horizontallayout_2") self.pushbutton_5 = qtwidgets.qpushbutton(self.centralwidget) self.pushbutton_5.setobjectname("pushbutton_5") self.horizontallayout_2.addwidget(self.pushbutton_5) self.verticallayout.addlayout(self.horizontallayout_2) self.verticallayout_4 = qtwidgets.qvboxlayout() self.verticallayout_4.setcontentsmargins(11, 11, 11, 11) self.verticallayout_4.setspacing(6) self.verticallayout_4.setobjectname("verticallayout_4") self.horizontallayout_4 = qtwidgets.qhboxlayout() self.horizontallayout_4.setcontentsmargins(11, 11, 11, 11) self.horizontallayout_4.setspacing(6) self.horizontallayout_4.setobjectname("horizontallayout_4") self.listview = qtwidgets.qlistview(self.centralwidget) self.listview.setdragdropmode(qtwidgets.qabstractitemview.dragdrop) self.listview.setviewmode(qtwidgets.qlistview.listmode) self.listview.setobjectname("listview") self.horizontallayout_4.addwidget(self.listview) self.textedit = qtwidgets.qtextedit(self.centralwidget) self.textedit.setobjectname("textedit") self.horizontallayout_4.addwidget(self.textedit) self.verticallayout_4.addlayout(self.horizontallayout_4) self.verticallayout.addlayout(self.verticallayout_4) self.horizontalslider = qtwidgets.qslider(self.centralwidget) self.horizontalslider.setorientation(qtcore.qt.horizontal) self.horizontalslider.setobjectname("horizontalslider") self.verticallayout.addwidget(self.horizontalslider) self.verticallayout_2 = qtwidgets.qvboxlayout() self.verticallayout_2.setcontentsmargins(11, 11, 11, 11) self.verticallayout_2.setspacing(6) self.verticallayout_2.setobjectname("verticallayout_2") self.horizontallayout = qtwidgets.qhboxlayout() self.horizontallayout.setcontentsmargins(11, 11, 11, 11) self.horizontallayout.setspacing(6) self.horizontallayout.setobjectname("horizontallayout") self.pushbutton_3 = qtwidgets.qpushbutton(self.centralwidget) self.pushbutton_3.setobjectname("pushbutton_3") self.horizontallayout.addwidget(self.pushbutton_3) self.pushbutton_2 = qtwidgets.qpushbutton(self.centralwidget) self.pushbutton_2.setobjectname("pushbutton_2") self.horizontallayout.addwidget(self.pushbutton_2) self.pushbutton = qtwidgets.qpushbutton(self.centralwidget) self.pushbutton.setobjectname("pushbutton") self.horizontallayout.addwidget(self.pushbutton) self.horizontallayout_3 = qtwidgets.qhboxlayout() self.horizontallayout_3.setcontentsmargins(11, 11, 11, 11) self.horizontallayout_3.setspacing(6) self.horizontallayout_3.setobjectname("horizontallayout_3") self.dial = qtwidgets.qdial(self.centralwidget) self.dial.setcursor(qtgui.qcursor(qtcore.qt.pointinghandcursor)) self.dial.setmousetracking(true) self.dial.setobjectname("dial") self.horizontallayout_3.addwidget(self.dial) self.pushbutton_4 = qtwidgets.qpushbutton(self.centralwidget) self.pushbutton_4.setobjectname("pushbutton_4") self.horizontallayout_3.addwidget(self.pushbutton_4) self.horizontallayout.addlayout(self.horizontallayout_3) self.verticallayout_2.addlayout(self.horizontallayout) self.verticallayout.addlayout(self.verticallayout_2) mainwindow.setcentralwidget(self.centralwidget) self.menubar = qtwidgets.qmenubar(mainwindow) self.menubar.setgeometry(qtcore.qrect(0, 0, 764, 21)) self.menubar.setobjectname("menubar") mainwindow.setmenubar(self.menubar) self.maintoolbar = qtwidgets.qtoolbar(mainwindow) self.maintoolbar.setobjectname("maintoolbar") mainwindow.addtoolbar(qtcore.qt.toptoolbararea, self.maintoolbar) self.statusbar = qtwidgets.qstatusbar(mainwindow) self.statusbar.setobjectname("statusbar") mainwindow.setstatusbar(self.statusbar) self.retranslateui(mainwindow) qtcore.qmetaobject.connectslotsbyname(mainwindow) self.pushbutton_5.clicked.connect(self.additem) def retranslateui(self, mainwindow): _translate = qtcore.qcoreapplication.translate mainwindow.setwindowtitle(_translate("mainwindow", "mainwindow")) self.pushbutton_5.settext(_translate("mainwindow", "show movies")) self.pushbutton_3.settext(_translate("mainwindow", "fast-forward")) self.pushbutton_2.settext(_translate("mainwindow", "pause/play")) self.pushbutton.settext(_translate("mainwindow", "rewind")) self.pushbutton_4.settext(_translate("mainwindow", "full screen")) def additem(self): open('moviedir.txt', 'r') moviedir: row in moviedir: listwidget.additem(row) if __name__ == "__main__": import sys app = qtwidgets.qapplication(sys.argv) mainwindow = qtwidgets.qmainwindow() ui = ui_mainwindow() ui.setupui(mainwindow) mainwindow.show() sys.exit(app.exec_())
self.listwidget = qtwidgets.qlistwidget(self.centralwidget) self.listwidget.setobjectname("listwidget") self.horizontallayout_4.addwidget(self.listwidget) open('moviesdir.txt','r') moviedir: movie in moviedir: self.listwidget.additem(movie)
this did asked, shows text, there way show files @ directory instead of directory string?
Comments
Post a Comment