28-12-2018, 10:01 PM
buenas tardes amigos mi pregunta es simple he creado un formulario principal y uno secundario, el principal es un QMAinWindow y el secundario un QDialog, lomando a llamar desde un menu todo bien mi pregunta es como hago para que el icono de mi form principal tambien aparesca en el form secundario, osea que se herede el icono, gracias de antemano aquí dejo el codigo de mi app. tambien adjunto la carpeta completa.
ventana principal:
ventana secundaria:
ventana principal:
Código:
from PyQt5 import QtCore, QtGui, QtWidgets
from dialog import Ui_Dialog
class Ui_MainWindow(QtWidgets.QMainWindow):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(400, 300)
MainWindow.setWindowIcon(QtGui.QIcon("app.png"))
self.centralWidget = QtWidgets.QWidget(MainWindow)
self.centralWidget.setObjectName("centralWidget")
MainWindow.setCentralWidget(self.centralWidget)
self.menuBar = QtWidgets.QMenuBar(MainWindow)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 400, 21))
self.menuBar.setObjectName("menuBar")
self.menu_File = QtWidgets.QMenu(self.menuBar)
self.menu_File.setObjectName("menu_File")
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.action_Open = QtWidgets.QAction(MainWindow)
self.action_Open.setObjectName("action_Open")
self.menu_File.addAction(self.action_Open)
self.menuBar.addAction(self.menu_File.menuAction())
self.action_Open.triggered.connect(self.openDialog)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def openDialog(self):
Dialog = QtWidgets.QDialog(Ui_MainWindow)
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.exec_()
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.menu_File.setTitle(_translate("MainWindow", "&File"))
self.action_Open.setText(_translate("MainWindow", "&Open"))
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_())
ventana secundaria:
Código:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(QtWidgets.QDialog):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))