Я пытаюсь встроить виджет графика в мое окно pyqt5. Я создал главное окно в дизайнере, используя виджет graphview для продвижения виджета pyqtgraph. Затем я экспортировал файл пользовательского интерфейса в код python, используя pyuic5.
Когда я запускаю код в своей среде python, я получаю никаких ошибок, и окно отображается на панели задач ... но выиграл не показывать должным образом. Когда я нажимаю на предварительный просмотр на панели задач, он не отображается в полном представлении. См.
Вид панели задач gui показывает, что все в порядке, но при нажатии не отменяется сведение
У меня есть пробовал это с обоими matplotlib и pyqtgraph и имел ту же самую проблему (окно, показываемое на панели задач, но не минимизация при нажатии). Это то, как я пытался встроить график? Любая помощь будет принята с благодарностью.
Для справки все мои другие pyqt5 gui windows без продвинутых виджетов работают нормально, кажется, только эти два с графиками.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QApplication
from pyqtgraph import PlotWidget
import icons
class Ui_reportWindow(object):
def setupUi(self, reportWindow):
reportWindow.setObjectName("reportWindow")
reportWindow.resize(1057, 663)
reportWindow.setMinimumSize(QtCore.QSize(1057, 663))
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/report_icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
reportWindow.setWindowIcon(icon)
reportWindow.setWindowOpacity(0.0)
self.centralwidget = QtWidgets.QWidget(reportWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox.setMaximumSize(QtCore.QSize(1041, 111))
self.groupBox.setObjectName("groupBox")
self.gridLayout_2 = QtWidgets.QGridLayout(self.groupBox)
self.gridLayout_2.setObjectName("gridLayout_2")
self.cbRoomNum = QtWidgets.QComboBox(self.groupBox)
self.cbRoomNum.setObjectName("cbRoomNum")
self.gridLayout_2.addWidget(self.cbRoomNum, 0, 1, 2, 1)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.gridLayout_2.addItem(spacerItem, 0, 2, 2, 1)
self.line = QtWidgets.QFrame(self.groupBox)
self.line.setFrameShape(QtWidgets.QFrame.VLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
self.gridLayout_2.addWidget(self.line, 0, 3, 5, 1)
self.label_3 = QtWidgets.QLabel(self.groupBox)
self.label_3.setObjectName("label_3")
self.gridLayout_2.addWidget(self.label_3, 0, 5, 1, 1)
self.label_4 = QtWidgets.QLabel(self.groupBox)
self.label_4.setObjectName("label_4")
self.gridLayout_2.addWidget(self.label_4, 0, 7, 1, 1)
self.label_5 = QtWidgets.QLabel(self.groupBox)
self.label_5.setObjectName("label_5")
self.gridLayout_2.addWidget(self.label_5, 0, 9, 1, 1)
spacerItem1 = QtWidgets.QSpacerItem(20, 8, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.gridLayout_2.addItem(spacerItem1, 0, 11, 1, 1)
spacerItem2 = QtWidgets.QSpacerItem(41, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.gridLayout_2.addItem(spacerItem2, 1, 4, 2, 1)
spacerItem3 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.gridLayout_2.addItem(spacerItem3, 1, 6, 2, 1)
spacerItem4 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.gridLayout_2.addItem(spacerItem4, 1, 8, 2, 1)
spacerItem5 = QtWidgets.QSpacerItem(41, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.gridLayout_2.addItem(spacerItem5, 1, 10, 2, 1)
self.pbGenerateReport = QtWidgets.QPushButton(self.groupBox)
self.pbGenerateReport.setObjectName("pbGenerateReport")
self.gridLayout_2.addWidget(self.pbGenerateReport, 1, 11, 2, 1)
spacerItem6 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.gridLayout_2.addItem(spacerItem6, 1, 12, 2, 1)
self.label_2 = QtWidgets.QLabel(self.groupBox)
self.label_2.setObjectName("label_2")
self.gridLayout_2.addWidget(self.label_2, 2, 0, 2, 1)
self.tbReportNum = QtWidgets.QLineEdit(self.groupBox)
self.tbReportNum.setObjectName("tbReportNum")
self.gridLayout_2.addWidget(self.tbReportNum, 2, 1, 2, 1)
spacerItem7 = QtWidgets.QSpacerItem(20, 23, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.gridLayout_2.addItem(spacerItem7, 3, 7, 2, 1)
spacerItem8 = QtWidgets.QSpacerItem(20, 23, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.gridLayout_2.addItem(spacerItem8, 3, 9, 2, 1)
spacerItem9 = QtWidgets.QSpacerItem(20, 23, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.gridLayout_2.addItem(spacerItem9, 3, 11, 2, 1)
self.pbTenHours = QtWidgets.QPushButton(self.groupBox)
self.pbTenHours.setObjectName("pbTenHours")
self.gridLayout_2.addWidget(self.pbTenHours, 3, 5, 2, 1)
self.tbTotalTime = QtWidgets.QLineEdit(self.groupBox)
self.tbTotalTime.setObjectName("tbTotalTime")
self.gridLayout_2.addWidget(self.tbTotalTime, 1, 9, 2, 1)
self.label = QtWidgets.QLabel(self.groupBox)
self.label.setObjectName("label")
self.gridLayout_2.addWidget(self.label, 0, 0, 2, 1)
self.sbStopTime = QtWidgets.QDateTimeEdit(self.groupBox)
self.sbStopTime.setButtonSymbols(QtWidgets.QAbstractSpinBox.UpDownArrows)
self.sbStopTime.setKeyboardTracking(False)
self.sbStopTime.setMaximumTime(QtCore.QTime(23, 59, 59))
self.sbStopTime.setCalendarPopup(True)
self.sbStopTime.setCurrentSectionIndex(0)
self.sbStopTime.setObjectName("sbStopTime")
self.gridLayout_2.addWidget(self.sbStopTime, 1, 7, 2, 1)
self.sbStartTime = QtWidgets.QDateTimeEdit(self.groupBox)
self.sbStartTime.setMaximumDateTime(QtCore.QDateTime(QtCore.QDate(2000, 1, 1), QtCore.QTime(23, 59, 59)))
self.sbStartTime.setCalendarPopup(True)
self.sbStartTime.setObjectName("sbStartTime")
self.gridLayout_2.addWidget(self.sbStartTime, 1, 5, 2, 1)
self.verticalLayout.addWidget(self.groupBox)
self.reportPlot = PlotWidget(self.centralwidget)
self.reportPlot.setObjectName("reportPlot")
self.verticalLayout.addWidget(self.reportPlot)
self.progressBar = QtWidgets.QProgressBar(self.centralwidget)
self.progressBar.setProperty("value", 56)
self.progressBar.setOrientation(QtCore.Qt.Horizontal)
self.progressBar.setInvertedAppearance(False)
self.progressBar.setObjectName("progressBar")
self.verticalLayout.addWidget(self.progressBar)
reportWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(reportWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1057, 21))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
self.menuSettings = QtWidgets.QMenu(self.menubar)
self.menuSettings.setObjectName("menuSettings")
self.menu_Help = QtWidgets.QMenu(self.menubar)
self.menu_Help.setObjectName("menu_Help")
self.menu_Export = QtWidgets.QMenu(self.menubar)
self.menu_Export.setObjectName("menu_Export")
reportWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(reportWindow)
self.statusbar.setObjectName("statusbar")
reportWindow.setStatusBar(self.statusbar)
self.action_User_Manual = QtWidgets.QAction(reportWindow)
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(":/userManual_icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_User_Manual.setIcon(icon1)
self.action_User_Manual.setObjectName("action_User_Manual")
self.action_Save = QtWidgets.QAction(reportWindow)
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(":/save_icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_Save.setIcon(icon2)
self.action_Save.setObjectName("action_Save")
self.action_Return_Home = QtWidgets.QAction(reportWindow)
icon3 = QtGui.QIcon()
icon3.addPixmap(QtGui.QPixmap(":/home_icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_Return_Home.setIcon(icon3)
self.action_Return_Home.setObjectName("action_Return_Home")
self.actionExcel_File = QtWidgets.QAction(reportWindow)
icon4 = QtGui.QIcon()
icon4.addPixmap(QtGui.QPixmap(":/excelFile_icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionExcel_File.setIcon(icon4)
self.actionExcel_File.setObjectName("actionExcel_File")
self.actionPDF_File = QtWidgets.QAction(reportWindow)
icon5 = QtGui.QIcon()
icon5.addPixmap(QtGui.QPixmap(":/pdfFile_icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionPDF_File.setIcon(icon5)
self.actionPDF_File.setObjectName("actionPDF_File")
self.actionLog_In = QtWidgets.QAction(reportWindow)
icon6 = QtGui.QIcon()
icon6.addPixmap(QtGui.QPixmap(":/adminOn_icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionLog_In.setIcon(icon6)
self.actionLog_In.setObjectName("actionLog_In")
self.actionLog_Out = QtWidgets.QAction(reportWindow)
icon7 = QtGui.QIcon()
icon7.addPixmap(QtGui.QPixmap(":/adminOff_icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionLog_Out.setIcon(icon7)
self.actionLog_Out.setObjectName("actionLog_Out")
self.actionCSV_File = QtWidgets.QAction(reportWindow)
icon8 = QtGui.QIcon()
icon8.addPixmap(QtGui.QPixmap(":/csvFile_icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionCSV_File.setIcon(icon8)
self.actionCSV_File.setObjectName("actionCSV_File")
self.action_Print = QtWidgets.QAction(reportWindow)
self.action_Print.setObjectName("action_Print")
self.menuFile.addAction(self.action_Print)
self.menuFile.addSeparator()
self.menuFile.addAction(self.action_Return_Home)
self.menuSettings.addAction(self.actionLog_In)
self.menuSettings.addAction(self.actionLog_Out)
self.menu_Help.addAction(self.action_User_Manual)
self.menu_Export.addAction(self.actionExcel_File)
self.menu_Export.addAction(self.actionPDF_File)
self.menu_Export.addAction(self.actionCSV_File)
self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menu_Export.menuAction())
self.menubar.addAction(self.menuSettings.menuAction())
self.menubar.addAction(self.menu_Help.menuAction())
self.retranslateUi(reportWindow)
QtCore.QMetaObject.connectSlotsByName(reportWindow)
def retranslateUi(self, reportWindow):
_translate = QtCore.QCoreApplication.translate
reportWindow.setWindowTitle(_translate("reportWindow", "Report"))
self.groupBox.setTitle(_translate("reportWindow", "Set Parameters"))
self.label_3.setText(_translate("reportWindow", " Start:"))
self.label_4.setText(_translate("reportWindow", "Report End:"))
self.label_5.setText(_translate("reportWindow", "Report Length:"))
self.pbGenerateReport.setText(_translate("reportWindow", "Generate Report"))
self.label_2.setText(_translate("reportWindow", "Enter Report Number:"))
self.pbTenHours.setText(_translate("reportWindow", "-24 hours"))
self.label.setText(_translate("reportWindow", "Select Room:"))
self.sbStopTime.setDisplayFormat(_translate("reportWindow", "yyyy/mm/dd hh:mm "))
self.sbStartTime.setDisplayFormat(_translate("reportWindow", "yyyy/mm/dd hh:mm "))
self.menuFile.setTitle(_translate("reportWindow", "&File"))
self.menuSettings.setTitle(_translate("reportWindow", "&Settings"))
self.menu_Help.setTitle(_translate("reportWindow", "&Help"))
self.menu_Export.setTitle(_translate("reportWindow", "&Export"))
self.action_User_Manual.setText(_translate("reportWindow", "&User Manual"))
self.action_Save.setText(_translate("reportWindow", "&Save"))
self.action_Save.setShortcut(_translate("reportWindow", "Ctrl+S"))
self.action_Return_Home.setText(_translate("reportWindow", "&Return Home"))
self.action_Return_Home.setShortcut(_translate("reportWindow", "Ctrl+W"))
self.actionExcel_File.setText(_translate("reportWindow", "&Excel File"))
self.actionPDF_File.setText(_translate("reportWindow", "&PDF File"))
self.actionLog_In.setText(_translate("reportWindow", "Log In"))
self.actionLog_In.setShortcut(_translate("reportWindow", "Ctrl+L"))
self.actionLog_Out.setText(_translate("reportWindow", "Log Out"))
self.actionLog_Out.setShortcut(_translate("reportWindow", "Ctrl+O"))
self.actionCSV_File.setText(_translate("reportWindow", "&CSV File"))
self.action_Print.setText(_translate("reportWindow", "&Print"))
class chamberReportWindow(QMainWindow):
def __init__(self, parent=None):
# QMainWindow.__init__(self)
super(chamberReportWindow,self).__init__()
self.parent = parent
self.ui = Ui_reportWindow()
self.ui.setupUi(self)
def update_graph(self):
pass
#this is module testing code can be deleted when incorporated into the main gui
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
window = chamberReportWindow()
window.show()
sys.exit(app.exec_())