python - PyQt5, click menu and open new window -
i have used qt designer create 2 different windows, input_window.ui , help_window.ui. here python scripts showing input window. in input window, there menu bar("about>>help"). how pop help_window when "help" clicked?
here init.py
import sys input_window import ui_mainwindow pyqt5.qtwidgets import qmainwindow, qapplication help_window import ui_help class mainwindow(qmainwindow, ui_mainwindow): def __init__(self, parent=none): super(mainwindow, self).__init__(parent) self.setupui(self) self.pophelp.triggered.connect(self.ui_help) def help_window(self): self.window=ui_help() self.window.show() if __name__ == "__main__": app = qapplication(sys.argv) window = mainwindow() window.show() sys.exit(app.exec_())
here code of ui_help
from pyqt5 import qtcore, qtgui, qtwidgets class ui_help(object): def setupui(self, help): help.setobjectname("help") help.resize(251, 99) icon = qtgui.qicon() icon.addpixmap(qtgui.qpixmap("logo.png"), qtgui.qicon.normal, qtgui.qicon.off) help.setwindowicon(icon) self.gridlayoutwidget = qtwidgets.qwidget(help) self.gridlayoutwidget.setgeometry(qtcore.qrect(9, 9, 231, 81)) self.gridlayoutwidget.setobjectname("gridlayoutwidget") self.gridlayout = qtwidgets.qgridlayout(self.gridlayoutwidget) self.gridlayout.setcontentsmargins(0, 0, 0, 0) self.gridlayout.setobjectname("gridlayout") self.plaintextedit = qtwidgets.qplaintextedit(self.gridlayoutwidget) font = qtgui.qfont() font.setfamily("times new roman") font.setpointsize(10) font.setbold(true) font.setweight(75) self.plaintextedit.setfont(font) self.plaintextedit.setframeshape(qtwidgets.qframe.winpanel) self.plaintextedit.setframeshadow(qtwidgets.qframe.sunken) self.plaintextedit.setlinewidth(1) self.plaintextedit.setsizeadjustpolicy(qtwidgets.qabstractscrollarea.adjustignored) self.plaintextedit.setreadonly(true) self.plaintextedit.setobjectname("plaintextedit") self.gridlayout.addwidget(self.plaintextedit, 0, 0, 1, 1) self.retranslateui(help) qtcore.qmetaobject.connectslotsbyname(help)
qt designer serves implement view in simple way, , therefore class generates oriented view, , our job implement logic did ui_mainwindow
, mainwindow
, ui_help
. in case recommend when have built help_window.ui
have used dialog template, if chose widget template there no problem, both compatible.
a simple solution create qdialog
, implement in ui_help
view shown below:
class mainwindow(qmainwindow, ui_mainwindow): def __init__(self, parent=none): super(mainwindow, self).__init__(parent) self.setupui(self) self.pophelp.triggered.connect(self.help_window) def help_window(self): # if pass parent (self) block main window, # , if not pass both independent, # recommend try both cases. widget = qdialog(self) ui=ui_help() ui.setupui(widget) widget.exec_()
if in ui_help
want implement logic recommend creating class similar mainwindow
shown below:
class help(qdialog, ui_help): def __init__(self, parent=none): super(help, self).__init__(parent) self.setupui(self) class mainwindow(qmainwindow, ui_mainwindow): def __init__(self, parent=none): super(mainwindow, self).__init__(parent) self.setupui(self) self.pophelp.triggered.connect(self.help_window) def help_window(self): widget = help() widget.exec_()
Comments
Post a Comment