def heightForWidth(self, width, defaultFont=None): """ Find the height for a given width :param float width: Width :param QFont defaultFont: Font, used for the calculation if the text has no font :return: Calculated height """ if defaultFont is None: defaultFont = QFont() font = QFont(self.usedFont(defaultFont), self._desktopwidget) h = 0 if self.__data.layoutAttributes & self.MinimumLayout: (left, right, top, bottom) = self.__data.textEngine.textMargins(font) h = self.__data.textEngine.heightForWidth(font, self.__data.renderFlags, self.__data.text, width + left + right) h -= top + bottom else: h = self.__data.textEngine.heightForWidth(font, self.__data.renderFlags, self.__data.text, width) return h
def styleQwtPlot(self,name,elem): font = QFont() font.setPixelSize(12) title = QwtText(name) title.setFont(font) elem.setTitle(title) canvas = elem.canvas() canvas.setLineWidth(0); elem.setCanvas(canvas)
def qwtUnscaleFont(painter): if painter.font().pixelSize() >= 0: return screenResolution = qwtScreenResolution() pd = painter.device() if pd.logicalDpiX() != screenResolution.width() or\ pd.logicalDpiY() != screenResolution.height(): pixelFont = QFont(painter.font(), QApplication.desktop()) pixelFont.setPixelSize(QFontInfo(pixelFont).pixelSize()) painter.setFont(pixelFont)
def qwtUnscaleFont(painter): if painter.font().pixelSize() >= 0: return screenResolution = qwtScreenResolution() pd = painter.device() if pd.logicalDpiX() != screenResolution.width() or\ pd.logicalDpiY() != screenResolution.height(): pixelFont = QFont(painter.font(), QApplication.desktop()) pixelFont.setPixelSize(QFontInfo(pixelFont).pixelSize()) painter.setFont(pixelFont)
def initAxesData(self): self.__axisData = [AxisData() for axisId in range(self.axisCnt)] self.__axisData[self.yLeft].scaleWidget = \ QwtScaleWidget(QwtScaleDraw.LeftScale, self) self.__axisData[self.yRight].scaleWidget = \ QwtScaleWidget(QwtScaleDraw.RightScale, self) self.__axisData[self.xTop].scaleWidget = \ QwtScaleWidget(QwtScaleDraw.TopScale, self) self.__axisData[self.xBottom].scaleWidget = \ QwtScaleWidget(QwtScaleDraw.BottomScale, self) self.__axisData[self.yLeft ].scaleWidget.setObjectName("QwtPlotAxisYLeft") self.__axisData[self.yRight ].scaleWidget.setObjectName("QwtPlotAxisYRight") self.__axisData[self.xTop ].scaleWidget.setObjectName("QwtPlotAxisXTop") self.__axisData[self.xBottom ].scaleWidget.setObjectName("QwtPlotAxisXBottom") fscl = QFont(self.fontInfo().family(), 10) fttl = QFont(self.fontInfo().family(), 12, QFont.Bold) for axisId in range(self.axisCnt): d = self.__axisData[axisId] d.scaleEngine = QwtLinearScaleEngine() d.scaleWidget.setTransformation(d.scaleEngine.transformation()) d.scaleWidget.setFont(fscl) d.scaleWidget.setMargin(2) text = d.scaleWidget.title() text.setFont(fttl) d.scaleWidget.setTitle(text) d.doAutoScale = True d.minValue = 0.0 d.maxValue = 1000.0 d.stepSize = 0.0 d.maxMinor = 5 d.maxMajor = 8 d.isValid = False self.__axisData[self.yLeft].isEnabled = True self.__axisData[self.yRight].isEnabled = False self.__axisData[self.xBottom].isEnabled = True self.__axisData[self.xTop].isEnabled = False
def draw(self, painter, rect): if self.__data.paintAttributes & self.PaintBackground: if self.__data.borderPen != Qt.NoPen or\ self.__data.backgroundBrush != Qt.NoBrush: painter.save() painter.setPen(self.__data.borderPen) painter.setBrush(self.__data.backgroundBrush) if self.__data.borderRadius == 0: QwtPainter.drawRect(painter, rect) else: painter.setRenderHint(QPainter.Antialiasing, True) painter.drawRoundedRect(rect, self.__data.borderRadius, self.__data.borderRadius) painter.restore() painter.save() if self.__data.paintAttributes & self.PaintUsingTextFont: painter.setFont(self.__data.font) if self.__data.paintAttributes & self.PaintUsingTextColor: if self.__data.color.isValid(): painter.setPen(self.__data.color) expandedRect = rect if self.__data.layoutAttributes & self.MinimumLayout: font = QFont(painter.font(), self.desktopwidget) (left, right, top, bottom) = self.__data.textEngine.textMargins(font) expandedRect.setTop(rect.top() - top) expandedRect.setBottom(rect.bottom() + bottom) expandedRect.setLeft(rect.left() - left) expandedRect.setRight(rect.right() + right) self.__data.textEngine.draw(painter, expandedRect, self.__data.renderFlags, self.__data.text) painter.restore()
def drawContents(self, painter): # draw curves r = self.contentsRect() dy = r.height() / len(self.curves) r.setHeight(dy) for curve in self.curves: self.xMap.setPaintInterval(r.left(), r.right()) self.yMap.setPaintInterval(r.top(), r.bottom()) engine = painter.device().paintEngine() if engine is not None and engine.hasFeature( QPaintEngine.Antialiasing): painter.setRenderHint( QPainter.Antialiasing, curve.testRenderHint(QwtPlotItem.RenderAntialiased)) curve.draw(painter, self.xMap, self.yMap, r) self.shiftDown(r, dy) # draw titles r = self.contentsRect() r.setHeight(dy) painter.setFont(QFont('Helvetica', 8)) painter.setPen(Qt.black) for title in self.titles: painter.drawText(0, r.top(), r.width(), painter.fontMetrics().height(), Qt.AlignTop | Qt.AlignHCenter, title) self.shiftDown(r, dy)
def show_layout_details(self): text = QwtText( "plotLayout().canvasRect():\n%r\n\n" "canvas().geometry():\n%r\n\n" "plotLayout().scaleRect(QwtPlot.yLeft):\n%r\n\n" "axisWidget(QwtPlot.yLeft).geometry():\n%r\n\n" "plotLayout().scaleRect(QwtPlot.yRight):\n%r\n\n" "axisWidget(QwtPlot.yRight).geometry():\n%r\n\n" "plotLayout().scaleRect(QwtPlot.xBottom):\n%r\n\n" "axisWidget(QwtPlot.xBottom).geometry():\n%r\n\n" "plotLayout().scaleRect(QwtPlot.xTop):\n%r\n\n" "axisWidget(QwtPlot.xTop).geometry():\n%r\n\n" % ( self.plotLayout().canvasRect().getCoords(), self.canvas().geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.yLeft).getCoords(), self.axisWidget(QwtPlot.yLeft).geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.yRight).getCoords(), self.axisWidget(QwtPlot.yRight).geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.xBottom).getCoords(), self.axisWidget(QwtPlot.xBottom).geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.xTop).getCoords(), self.axisWidget(QwtPlot.xTop).geometry().getCoords(), )) text.setFont(QFont('Courier New')) text.setColor(Qt.blue) self.marker.setLabel(text)
def __init__(self): self.isEnabled = None self.scaleWidget = QwtScaleWidget() self.scaleFont = QFont() self.start = None self.end = None self.baseLineOffset = None self.tickOffset = None self.dimWithoutTitle = None
def heightForWidth(self, width, defaultFont=None): if defaultFont is None: defaultFont = QFont() font = QFont(self.usedFont(defaultFont), self.desktopwidget) h = 0 if self.__data.layoutAttributes & self.MinimumLayout: (left, right, top, bottom) = self.__data.textEngine.textMargins(font) h = self.__data.textEngine.heightForWidth(font, self.__data.renderFlags, self.__data.text, width + left + right) h -= top + bottom else: h = self.__data.textEngine.heightForWidth(font, self.__data.renderFlags, self.__data.text, width) return h
def textSize(self, defaultFont): font = QFont(self.usedFont(defaultFont), self.desktopwidget) if not self.__layoutCache.textSize.isValid() or\ self.__layoutCache.font is not font: self.__layoutCache.textSize =\ self.__data.textEngine.textSize(font, self.__data.renderFlags, self.__data.text) self.__layoutCache.font = font sz = self.__layoutCache.textSize if self.__data.layoutAttributes & self.MinimumLayout: (left, right, top, bottom) = self.__data.textEngine.textMargins(font) sz -= QSizeF(left + right, top + bottom) return sz
def textSize(self, defaultFont): """ Returns the size, that is needed to render text :param QFont defaultFont Font, used for the calculation if the text has no font :return: Caluclated size """ font = QFont(self.usedFont(defaultFont), self._desktopwidget) if not self.__layoutCache.textSize.isValid() or\ self.__layoutCache.font is not font: self.__layoutCache.textSize =\ self.__data.textEngine.textSize(font, self.__data.renderFlags, self.__data.text) self.__layoutCache.font = font sz = self.__layoutCache.textSize if self.__data.layoutAttributes & self.MinimumLayout: (left, right, top, bottom) = self.__data.textEngine.textMargins(font) sz -= QSizeF(left + right, top + bottom) return sz
def create_2D_plotter(self): if not self.ND_plotter is None: self.ND_plotter.close() self.ND_plotter = None self.twoD_plotter, self.plotPrinter = plot_func.create_2D_Plotters( self.layout, self.layout_parent) self.twoD_plotter.colorbar_needed.connect(self.set_ColorBar) self.twoD_plotter.show_ND_Controller.connect( self.ND_controller_showDisplay) self.twoD_plotter.show_3D_Display.connect(self.show_3D_Display) self.twoD_plotter.do_print.connect(self.plotPrinter.do_print) self.twoD_plotter.save_display.connect(self.grab_display) # create status label display self.status_label = Qt.QLabel(self.layout_parent) sansFont = QFont("Helvetica [Cronyx]", 8) self.status_label.setFont(sansFont) # self.layout.addMultiCellWidget(self.status_label,1,1,0,2) self.layout.addWidget(self.status_label, 1, 0, 1, 2) self.status_label.setText("Move the mouse within the plot canvas" " to show the cursor position.") self.status_label.show() self.twoD_plotter.status_update.connect(self.update_status)
def __init__(self, *args): QMainWindow.__init__(self, *args) self.plot = DataPlot(self) self.plot.setContentsMargins(5, 5, 5, 0) self.setCentralWidget(self.plot) # signal slot connect self.plot.signal_showinfo.connect(self.showInfo) font = QFont() font.setFamily("Calibri") #,Consolas font.setPointSize(16) font2 = QFont() font2.setFamily("Calibri") font2.setPointSize(12) self.plot.setFont(font2) # add toolbar toolBar = QToolBar(self) toolBar.setOrientation(Qt.Vertical) self.addToolBar(toolBar) # label COM lbl_COM = QLabel("COM:", toolBar) lbl_COM.setFont(font2) lbl_COM.setStyleSheet("") toolBar.addWidget(lbl_COM) #lineEdit_COM self.lineEdit_COM = QLineEdit(str(config.Port)) self.lineEdit_COM.setFont(font2) #self.lineEdit_COM.setMinimumWidth(100) toolBar.addWidget(self.lineEdit_COM) # label baudrate lbl_baud = QLabel("BAUD Rate:", toolBar) lbl_baud.setFont(font2) lbl_baud.setStyleSheet("") toolBar.addWidget(lbl_baud) #lineEdit_baud self.lineEdit_baud = QLineEdit(str(config.BaudRate)) #self.lineEdit_baud.setMinimumWidth(100) self.lineEdit_baud.setFont(font2) toolBar.addWidget(self.lineEdit_baud) # Connect device, QIcon(const QString &filename); // 从图像文件构造图标 btnConnect = QToolButton(toolBar) btnConnect.setText("Connect") btnConnect.setFont(font2) btnConnect.setIcon(QIcon('./icon/Connect.png')) btnConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnConnect) btnConnect.clicked.connect(self.GetComSettings_Connect) # disConnect device btnDisConnect = QToolButton(toolBar) btnDisConnect.setText("DisConnect") btnDisConnect.setFont(font2) btnDisConnect.setIcon(QIcon('./icon/Disconnect.jfif')) btnDisConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnDisConnect) btnDisConnect.clicked.connect(self.plot.DisConnect) toolBar.addSeparator() # Start timer btnStartTimer = QToolButton(toolBar) btnStartTimer.setText("Start Timer") btnStartTimer.setFont(font2) btnStartTimer.setIcon(QIcon('./icon/start.jfif')) btnStartTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnStartTimer) btnStartTimer.clicked.connect(self.plot.StartTimer) # Stop timer btnStopTimer = QToolButton(toolBar) btnStopTimer.setText("Stop Timer") btnStopTimer.setFont(font2) btnStopTimer.setIcon(QIcon('./icon/stop.jfif')) btnStopTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnStopTimer) btnStopTimer.clicked.connect(self.plot.StopTimer) toolBar.addSeparator() #X_LOWER lbl_x_lower = QLabel("X-Lower:", toolBar) lbl_x_lower.setFont(font2) toolBar.addWidget(lbl_x_lower) self.LineEdit_x_lower = QLineEdit(str(config.X_lower), toolBar) self.LineEdit_x_lower.setFont(font2) toolBar.addWidget(self.LineEdit_x_lower) #X_Upper lbl_x_upper = QLabel("X-Upper:", toolBar) lbl_x_upper.setFont(font2) toolBar.addWidget(lbl_x_upper) self.LineEdit_x_upper = QLineEdit(str(config.X_upper), toolBar) self.LineEdit_x_upper.setFont(font2) toolBar.addWidget(self.LineEdit_x_upper) #X_interval lbl_x_inteval = QLabel("X-Interval(s):", toolBar) lbl_x_inteval.setFont(font2) toolBar.addWidget(lbl_x_inteval) self.LineEdit_x_interval = QLineEdit(str(config.X_grid_interval), toolBar) self.LineEdit_x_interval.setFont(font2) toolBar.addWidget(self.LineEdit_x_interval) # Y_Lower lbl_y_lower = QLabel("Y-Lower:", toolBar) lbl_y_lower.setFont(font2) toolBar.addWidget(lbl_y_lower) self.LineEdit_y_Lower = QLineEdit(str(config.Y_lower), toolBar) self.LineEdit_y_Lower.setFont(font2) toolBar.addWidget(self.LineEdit_y_Lower) # Y_Upper lbl_y_uppwer = QLabel("Y-Upper:", toolBar) lbl_y_uppwer.setFont(font2) toolBar.addWidget(lbl_y_uppwer) self.LineEdit_Y_Upper = QLineEdit(str(config.Y_upper), toolBar) self.LineEdit_Y_Upper.setFont(font2) toolBar.addWidget(self.LineEdit_Y_Upper) # Y-Interval lbl_Y_Interval = QLabel("Y-Interval:", toolBar) lbl_Y_Interval.setFont(font2) toolBar.addWidget(lbl_Y_Interval) self.LineEdit_y_interval = QLineEdit(str(config.Y_grid_interval), toolBar) self.LineEdit_y_interval.setFont(font2) toolBar.addWidget(self.LineEdit_y_interval) # Set axis para btnSet = QToolButton(toolBar) btnSet.setText("Set Paras") btnSet.setFont(font2) btnSet.setIcon(QIcon('./icon/Settings.jfif')) btnSet.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnSet) btnSet.clicked.connect(self.SetParas) toolBar.addSeparator() # add print btn to toolbar btnPrint = QToolButton(toolBar) btnPrint.setText("Print") btnPrint.setFont(font2) btnPrint.setIcon(QIcon('./icon/print.jfif')) btnPrint.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnPrint) btnPrint.clicked.connect(self.print_) # add Export btn to toolbar btnExport = QToolButton(toolBar) btnExport.setText("Export") btnExport.setFont(font2) btnExport.setIcon(QIcon('./icon/snapshot.jfif')) btnExport.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnExport) btnExport.clicked.connect(self.exportDocument) toolBar.addSeparator() # add About btn to toolbar btnAbout = QToolButton(toolBar) btnAbout.setText("About") btnAbout.setFont(font2) btnAbout.setIcon(QIcon('./icon/about.png')) btnAbout.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnAbout) btnAbout.clicked.connect(self.About) #self.statusBar().setStyleSheet("QStatusBar::item{border: 5px}") self.statusBar().setStyleSheet("color:green") #self.statusBar().addPermanentWidget(VLine()) self.statusBar().addPermanentWidget(QLabel("X = ")) #self.statusBar().addPermanentWidget(VLine()) self.statusBar().addPermanentWidget(QLabel("Y = ")) #self.statusBar().addPermanentWidget(VLine()) PermanentLabel = QLabel("Version:" + kProgVersion + " Developed by " + kProgramDeveloperName + " Python. Running with " + kPythonVersion) font3 = QFont() font3.setFamily("Calibri") font3.setPointSize(12) PermanentLabel.setFont(font3) self.statusBar().setFont(font3) self.statusBar().addPermanentWidget(PermanentLabel) self.showInfo("Show info here ......")
def styleQwtPlot(self, name, elem): font = QFont() font.setPixelSize(24) title = QwtText(name) title.setFont(font) elem.setTitle(title)
def axisFont(self, axisId): if self.axisValid(axisId): return self.axisWidget(axisId).font() else: return QFont()
def __init__(self, *args): QMainWindow.__init__(self, *args) self.plot = DataPlot(self) #self.plot.resize(540,760) self.plot.setContentsMargins(5, 5, 5, 0) self.setCentralWidget(self.plot) print(type(self.plot.signal_showinfo)) # signal slot connect self.plot.signal_showinfo.connect(self.showInfo) font = QFont() font.setFamily("Calibri") #,Consolas font.setPointSize(16) font2 = QFont() font2.setFamily("Calibri") font2.setPointSize(14) self.plot.setFont(font2) # add toolbar toolBar = QToolBar(self) self.addToolBar(toolBar) # label COM lbl_COM = QLabel("COM:",toolBar) lbl_COM.setFont(font) lbl_COM.setStyleSheet("") toolBar.addWidget(lbl_COM) #lineEdit_COM self.lineEdit_COM = QLineEdit('COM37') self.lineEdit_COM.setFont(font2) self.lineEdit_COM.setMinimumWidth(50) toolBar.addWidget(self.lineEdit_COM) # label baudrate lbl_baud = QLabel("BAUD Rate:",toolBar) lbl_baud.setFont(font) lbl_baud.setStyleSheet("") toolBar.addWidget(lbl_baud) #lineEdit_baud self.lineEdit_baud = QLineEdit('9600') self.lineEdit_baud.setMinimumWidth(100) self.lineEdit_baud.setFont(font2) toolBar.addWidget(self.lineEdit_baud) # label command lbl_command = QLabel("Command:",toolBar) lbl_command.setFont(font) lbl_command.setStyleSheet("") toolBar.addWidget(lbl_command) #lineEdit_command self.lineEdit_command = QLineEdit(r'UPPER_VAL?\r\n') self.lineEdit_command.setFont(font2) #self.lineEdit_command.resize(200,12) #self.lineEdit_command.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred) self.lineEdit_command.setMinimumWidth(300) toolBar.addWidget(self.lineEdit_command) # label response_rex lbl_response_rex = QLabel("response_rex:",toolBar) lbl_response_rex.setFont(font) lbl_response_rex.setStyleSheet("") toolBar.addWidget(lbl_response_rex) #lineEdit_response_rex self.lineEdit_response_rex = QLineEdit(r'^[-]?([0-9]{1,}[.]?[0-9]*)') self.lineEdit_response_rex.setFont(font2) #self.lineEdit_command.resize(200,12) #self.lineEdit_command.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred) self.lineEdit_response_rex.setMinimumWidth(300) toolBar.addWidget(self.lineEdit_response_rex) # Connect device, QIcon(const QString &filename); // 从图像文件构造图标 btnConnect = QToolButton(toolBar) btnConnect.setText("Connect") btnConnect.setFont(font2) btnConnect.setIcon(QIcon('./icon/Connect.png')) btnConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnConnect) btnConnect.clicked.connect(self.GetComSettings_Connect) # disConnect device btnDisConnect = QToolButton(toolBar) btnDisConnect.setText("DisConnect") btnDisConnect.setFont(font2) btnDisConnect.setIcon(QIcon('./icon/Disconnect.jfif')) btnDisConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnDisConnect) btnDisConnect.clicked.connect(self.plot.DisConnect) toolBar.addSeparator() # Label sample interval lbl_timer_interval = QLabel("Timer(ms):",toolBar) lbl_timer_interval.setFont(font) lbl_timer_interval.setStyleSheet("") toolBar.addWidget(lbl_timer_interval) # lineEdit sample interval self.lineEdit_timer_interval = QLineEdit('250') self.lineEdit_timer_interval.setFont(font2) self.lineEdit_timer_interval.setStyleSheet("") toolBar.addWidget(self.lineEdit_timer_interval) # Start timer btnStartTimer = QToolButton(toolBar) btnStartTimer.setText("Start Timer") btnStartTimer.setFont(font2) btnStartTimer.setIcon(QIcon('./icon/start.jfif')) btnStartTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnStartTimer) btnStartTimer.clicked.connect(self.plot.StartTimer) # Stop timer btnStopTimer = QToolButton(toolBar) btnStopTimer.setText("Stop Timer") btnStopTimer.setFont(font2) btnStopTimer.setIcon(QIcon('./icon/stop.jfif')) btnStopTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnStopTimer) btnStopTimer.clicked.connect(self.plot.StopTimer) toolBar.addSeparator() # dampBox = QWidget(toolBar) # dampLayout = QHBoxLayout(dampBox) # dampLayout.setSpacing(0) # dampLayout.addWidget(QWidget(dampBox), 0) # spacer #X_interval lbl_x_inteval = QLabel("X-Interval(s):", toolBar) lbl_x_inteval.setFont(font) #dampLayout.addWidget(lbl_x_inteval, 0) toolBar.addWidget(lbl_x_inteval) self.LineEdit_x_interval= QLineEdit('30',toolBar) self.LineEdit_x_interval.setFont(font2) #dampLayout.addWidget(self.LineEdit_x_interval,0) #dampLayout.addSpacing(10) toolBar.addWidget(self.LineEdit_x_interval) # Y_Lower lbl_y_lower = QLabel("Y-Lower:", toolBar) lbl_y_lower.setFont(font) #dampLayout.addWidget(lbl_y_lower, 0) toolBar.addWidget(lbl_y_lower) self.LineEdit_y_Lower = QLineEdit('-90', toolBar) self.LineEdit_y_Lower.setFont(font2) #dampLayout.addWidget(self.LineEdit_y_Lower, 0) #dampLayout.addSpacing(10) toolBar.addWidget(self.LineEdit_y_Lower) # Y_Upper lbl_y_uppwer = QLabel("Y-Upper:", toolBar) lbl_y_uppwer.setFont(font) #dampLayout.addWidget(lbl_y_uppwer, 0) toolBar.addWidget(lbl_y_uppwer) self.LineEdit_Y_Upper = QLineEdit('210', toolBar) self.LineEdit_Y_Upper.setFont(font2) #dampLayout.addWidget(self.LineEdit_Y_Upper, 0) #dampLayout.addSpacing(10) toolBar.addWidget(self.LineEdit_Y_Upper) # Y-Interval lbl_Y_Interval = QLabel("Y-Interval:", toolBar) lbl_Y_Interval.setFont(font) #dampLayout.addWidget(lbl_Y_Interval, 0) toolBar.addWidget(lbl_Y_Interval) self.LineEdit_y_interval= QLineEdit('50', toolBar) self.LineEdit_y_interval.setFont(font2) #dampLayout.addWidget(self.LineEdit_y_interval, 0) #dampLayout.addSpacing(10) toolBar.addWidget(self.LineEdit_y_interval) #toolBar.addWidget(dampBox) # Set axis para btnSet = QToolButton(toolBar) btnSet.setText("Set Paras") btnSet.setFont(font2) btnSet.setIcon(QIcon('./icon/Settings.jfif')) btnSet.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnSet) btnSet.clicked.connect(self.SetParas) toolBar.addSeparator() # add print btn to toolbar btnPrint = QToolButton(toolBar) btnPrint.setText("Print") btnPrint.setFont(font2) btnPrint.setIcon(QIcon('./icon/print.jfif')) btnPrint.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnPrint) btnPrint.clicked.connect(self.print_) # add Export btn to toolbar btnExport = QToolButton(toolBar) btnExport.setText("Export") btnExport.setFont(font2) btnExport.setIcon(QIcon('./icon/snapshot.jfif')) btnExport.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnExport) btnExport.clicked.connect(self.exportDocument) toolBar.addSeparator() self.statusBar() self.showInfo("Show info here ......")
def font(self, f, _): result = QFont(f) result.setPointSize(int(f.pointSize() * 1.25)) return result
def __init__(self, *args): QwtPlot.__init__(self, *args) self.uut_dev = None self.timerId = None self.interval = 250 # ms fileTIME = datetime.datetime.now() File_timestamp = "%04d-%02d-%02d_%02d%02d%02d" % (fileTIME.year,fileTIME.month,fileTIME.day,fileTIME.hour, fileTIME.minute, fileTIME.second) self.fileNamme = '.\data\data_%s.txt'%File_timestamp print(self.fileNamme) self.x_range = 180.1 self.x_interval = 10.0 self.y_range_Upper = 210.0 self.y_range_Lower = -90.0 self.y_interval = 20.0 self.unit = 'kPa' # default value, will replaced by actual reading. self.getReadingCommand = r"UPPER_VAL?\r\n" # default pass and pac self.getResp_rex = r'^[-]?([0-9]{1,}[.]?[0-9]*)' self.lenth = 40 # 10s caculate the slowrate # QwtPlot property # Initialize 坐标轴 self.setCanvasBackground(Qt.white) #Qt.white self.alignScales() grid = QwtPlotGrid() grid.attach(self) grid.setMajorPen(QPen(Qt.black, 0, Qt.DotLine)) self.setAxisScale(QwtPlot.xBottom, 0.0,self.x_range,self.x_interval) #self.setAxisAutoScale(QwtPlot.yLeft,True) #self.setAxisScale(QwtPlot.yLeft,99.99,100.0,0.0005) self.setAxisScale(QwtPlot.yLeft,self.y_range_Lower,self.y_range_Upper,self.y_interval) self.setAxisLabelRotation(QwtPlot.xBottom,-45.0) self.x = np.arange(0.0, self.x_range + 1, 0.25)#0.25 for ONE POINT, THIS SHOULD BE Align to the reading rate:250ms #self.z = np.zeros(len(self.x), np.float) list = [] for i in range(len(self.x)): list.append(0.0) self.z = np.array(list) rlist = [] for i in range(self.lenth): # 10s rlist.append(0.0) self.RateList = np.array(rlist) self.setTitle("UUT Reading Monitor - OutPort(%s)\r\n"%(self.unit)) self.insertLegend(QwtLegend(), QwtPlot.RightLegend); self.curveL = QwtPlotCurve("UUT Reading") self.curveL.attach(self) pen = QPen(Qt.red) pen.setWidth(1.5) self.curveL.setPen(pen) # show peak line and point value fn = self.fontInfo().family() self.peakMarker = m = QwtPlotMarker() m.setLineStyle(QwtPlotMarker.HLine) m.setLabelAlignment(Qt.AlignLeft | Qt.AlignTop) m.setLinePen(QPen(Qt.blue, 1.5, Qt.DashDotLine)) text = QwtText('dfdfdfdf') text.setColor(Qt.red) text.setBackgroundBrush(QBrush(self.canvasBackground())) text.setFont(QFont(fn, 12, QFont.Bold)) m.setLabel(text) # MarkPoint symbol m.setSymbol(QwtSymbol(QwtSymbol.Diamond, QBrush(Qt.blue), QPen(Qt.green), QSize(7,7))) m.attach(self) # text marker self.txtMarker = m = QwtPlotMarker() m.setValue(self.x_range/2, self.y_range_Upper - self.y_interval/2) # show position m.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom) text = QwtText('initial') text.setFont(QFont(fn, 20, QFont.Bold)) text.setColor(Qt.white) text.setBackgroundBrush(QBrush(Qt.black)) text.setBorderPen(QPen(Qt.red, 2)) m.setLabel(text) m.attach(self) self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)") self.setAxisTitle(QwtPlot.yLeft, "UUT - Reading(%s)"%(self.unit)) self.replot() #self.startTimer(250)#ms# FOR GET READING self.starttime = time.clock();#unit: s self.idx = 0 self.readfmt = "%f" self.Saveinfo("Starting...")
def __init__(self, *args): QMainWindow.__init__(self, *args) self.plot = DataPlot(self) self.plot.setContentsMargins(5, 5, 5, 0) self.setCentralWidget(self.plot) print(type(self.plot.signal_showinfo)) # signal slot connect self.plot.signal_showinfo.connect(self.showInfo) font = QFont() font.setFamily("Calibri") #,Consolas font.setPointSize(16) font2 = QFont() font2.setFamily("Calibri") font2.setPointSize(14) self.plot.setFont(font2) # add toolbar toolBar = QToolBar(self) self.addToolBar(toolBar) # label COM lbl_COM = QLabel("COM:", toolBar) lbl_COM.setFont(font) lbl_COM.setStyleSheet("") toolBar.addWidget(lbl_COM) #lineEdit_COM self.lineEdit_COM = QLineEdit(str(config.Port)) self.lineEdit_COM.setFont(font2) self.lineEdit_COM.setMinimumWidth(50) toolBar.addWidget(self.lineEdit_COM) # label baudrate lbl_baud = QLabel("BAUD Rate:", toolBar) lbl_baud.setFont(font) lbl_baud.setStyleSheet("") toolBar.addWidget(lbl_baud) #lineEdit_baud self.lineEdit_baud = QLineEdit(str(config.BaudRate)) self.lineEdit_baud.setMinimumWidth(100) self.lineEdit_baud.setFont(font2) toolBar.addWidget(self.lineEdit_baud) # Connect device, QIcon(const QString &filename); // 从图像文件构造图标 btnConnect = QToolButton(toolBar) btnConnect.setText("Connect") btnConnect.setFont(font2) btnConnect.setIcon(QIcon('./icon/Connect.png')) btnConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnConnect) btnConnect.clicked.connect(self.GetComSettings_Connect) # disConnect device btnDisConnect = QToolButton(toolBar) btnDisConnect.setText("DisConnect") btnDisConnect.setFont(font2) btnDisConnect.setIcon(QIcon('./icon/Disconnect.jfif')) btnDisConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnDisConnect) btnDisConnect.clicked.connect(self.plot.DisConnect) toolBar.addSeparator() # Start timer btnStartTimer = QToolButton(toolBar) btnStartTimer.setText("Start Timer") btnStartTimer.setFont(font2) btnStartTimer.setIcon(QIcon('./icon/start.jfif')) btnStartTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnStartTimer) btnStartTimer.clicked.connect(self.plot.StartTimer) # Stop timer btnStopTimer = QToolButton(toolBar) btnStopTimer.setText("Stop Timer") btnStopTimer.setFont(font2) btnStopTimer.setIcon(QIcon('./icon/stop.jfif')) btnStopTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnStopTimer) btnStopTimer.clicked.connect(self.plot.StopTimer) toolBar.addSeparator() #X_LOWER lbl_x_lower = QLabel("X-Lower:", toolBar) lbl_x_lower.setFont(font) toolBar.addWidget(lbl_x_lower) self.LineEdit_x_lower = QLineEdit(str(0), toolBar) self.LineEdit_x_lower.setFont(font2) toolBar.addWidget(self.LineEdit_x_lower) #X_Upper lbl_x_upper = QLabel("X-Upper:", toolBar) lbl_x_upper.setFont(font) toolBar.addWidget(lbl_x_upper) self.LineEdit_x_upper = QLineEdit(str(config.X_upper), toolBar) self.LineEdit_x_upper.setFont(font2) toolBar.addWidget(self.LineEdit_x_upper) #X_interval lbl_x_inteval = QLabel("X-Interval(s):", toolBar) lbl_x_inteval.setFont(font) toolBar.addWidget(lbl_x_inteval) self.LineEdit_x_interval = QLineEdit(str(config.X_grid_interval), toolBar) self.LineEdit_x_interval.setFont(font2) toolBar.addWidget(self.LineEdit_x_interval) # Y_Lower lbl_y_lower = QLabel("Y-Lower:", toolBar) lbl_y_lower.setFont(font) toolBar.addWidget(lbl_y_lower) self.LineEdit_y_Lower = QLineEdit(str(config.Y_lower), toolBar) self.LineEdit_y_Lower.setFont(font2) toolBar.addWidget(self.LineEdit_y_Lower) # Y_Upper lbl_y_uppwer = QLabel("Y-Upper:", toolBar) lbl_y_uppwer.setFont(font) toolBar.addWidget(lbl_y_uppwer) self.LineEdit_Y_Upper = QLineEdit(str(config.Y_upper), toolBar) self.LineEdit_Y_Upper.setFont(font2) toolBar.addWidget(self.LineEdit_Y_Upper) # Y-Interval lbl_Y_Interval = QLabel("Y-Interval:", toolBar) lbl_Y_Interval.setFont(font) toolBar.addWidget(lbl_Y_Interval) self.LineEdit_y_interval = QLineEdit(str(config.Y_grid_interval), toolBar) self.LineEdit_y_interval.setFont(font2) toolBar.addWidget(self.LineEdit_y_interval) # Set axis para btnSet = QToolButton(toolBar) btnSet.setText("Set Paras") btnSet.setFont(font2) btnSet.setIcon(QIcon('./icon/Settings.jfif')) btnSet.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnSet) btnSet.clicked.connect(self.SetParas) toolBar.addSeparator() # add print btn to toolbar btnPrint = QToolButton(toolBar) btnPrint.setText("Print") btnPrint.setFont(font2) btnPrint.setIcon(QIcon('./icon/print.jfif')) btnPrint.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnPrint) btnPrint.clicked.connect(self.print_) # add Export btn to toolbar btnExport = QToolButton(toolBar) btnExport.setText("Export") btnExport.setFont(font2) btnExport.setIcon(QIcon('./icon/snapshot.jfif')) btnExport.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnExport) btnExport.clicked.connect(self.exportDocument) toolBar.addSeparator() self.statusBar() self.showInfo("Show info here ......")
def __init__(self, colorbar_number=0, parent=None): QwtPlot.__init__(self, parent) self._mainwin = parent and parent.topLevelWidget() self.colorbar_number = colorbar_number # create copy of standard application font.. font = QFont() fi = QFontInfo(font) # and scale it down to 70% font.setPointSize(fi.pointSize() * 0.7) # apply font to QwtPlot # self.setTitleFont(font); for axis in range(0, 4): self.setAxisFont(axis, font) # self.setAxisTitleFont(axis,font); # make a QwtPlot widget self.plotLayout().setCanvasMargin(0) self.plotLayout().setAlignCanvasToScales(1) # set axis parameters self.enableAxis(QwtPlot.yLeft) self.enableAxis(QwtPlot.xBottom, False) self.setAxisLabelRotation(QwtPlot.yLeft, 270) self.setAxisLabelAlignment(QwtPlot.yLeft, Qt.AlignTop) # default color bar self.plotImage = QwtPlotImage(self) self.plotImage.attach(self) self.updateDisplay() self.min = 0.0 self.max = 256.0 self.is_active = False self.log_scale = False self.ampl_phase = False self.bar_array = numpy.reshape(numpy.arange(self.max), (1, 256)) self.y_scale = (self.min, self.max) self.plotImage.setData(self.bar_array, None, self.y_scale) # Over-ride default QWT Plot size policy of MinimumExpanding # Otherwise minimum size of plots is too large when embedded in a # QGridlayout self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) # width limits - the following seem reasonable # we don't want the bar to resize itself freely - it becomes too big! # self.setMaximumWidth(self.sizeHint().width() * 2.5) self.setMaximumWidth(self.sizeHint().width() * 1.5) self.spy = Spy(self.canvas()) self.spy.MouseMove.connect(self.MouseMoveEvent) self.spy.MousePress.connect(self.MousePressEvent) self.spy.MouseRelease.connect(self.MouseReleaseEvent) self.zoomStack = [] self.xzoom_loc = None self.yzoom_loc = None self.prev_xpos = None self.prev_ypos = None self.raw_image_min = None self.raw_image_max = None # create zoom curve self.zoom_outline = QwtPlotCurve() self.setMouseTracking(True) self.installEventFilter(self) # add intructions on how to use self.setWhatsThis(colorbar_instructions) # create pull_down menu and add menu components if self._mainwin: self._menu = QMenu(self._mainwin) else: self._menu = QMenu(None) self._unzoom_action = QAction('unzoom intensity range', self) self._menu.addAction(self._unzoom_action) self._unzoom_action.setVisible(False) self._unzoom_action.triggered.connect(self.unzoom) self._lock_colorbar = QAction('lock colorbar scale', self) self._menu.addAction(self._lock_colorbar) self._lock_colorbar.triggered.connect(self.lock_colorbar) self._unlock_colorbar = QAction('unlock colorbar scale', self) self._menu.addAction(self._unlock_colorbar) self._unlock_colorbar.setVisible(False) self._unlock_colorbar.triggered.connect(self.unlock_colorbar) self._lock_bar = False # for drag & drop stuff ... self.setAcceptDrops(True) self.yhb = 0 self.ylb = 0 self.xhb = 0 self.xlb = 0
def __init__(self, *args): QwtPlot.__init__(self, *args) self.uut_dev = None self.timerId = None #self.interval = 250 # ms self.interval = config.interval # ms fileTIME = datetime.datetime.now() File_timestamp = "%04d-%02d-%02d_%02d%02d%02d" % ( fileTIME.year, fileTIME.month, fileTIME.day, fileTIME.hour, fileTIME.minute, fileTIME.second) self.fileNamme = '.\data\data_%s.txt' % File_timestamp print('Raw data record file name:%s' % self.fileNamme) # default parameters from config file self.x_ZERO = config.X_lower self.x_range = config.X_upper self.x_interval = config.X_grid_interval self.y_range_Upper = config.Y_upper self.y_range_Lower = config.Y_lower self.y_interval = config.Y_grid_interval self.unit = 'kPa' # default value, will replaced by actual reading. #self.getReadingCommand = r"UPPER_VAL?\r\n" # default pass and pac #self.getResp_rex = r'^[-]?([0-9]{1,}[.]?[0-9]*)' self.lenth = config.Slope_lenth # 40 = 10s caculate the slowrate # QwtPlot property # Initialize 坐标轴 self.setCanvasBackground(Qt.white) #Qt.white self.alignScales() grid = QwtPlotGrid() grid.attach(self) grid.setMajorPen(QPen(Qt.black, 0, Qt.DotLine)) # x Axis property #self.setAxisScaleDraw(QwtPlot.xBottom, TimeScaleDraw(self.cpuStat.upTime())) #timeScale = QwtDateScaleDraw(Qt.LocalTime) #print(timeScale) #self.setAxisScaleDraw(QwtPlot.xBottom, timeScale) self.setAxisScale(QwtPlot.xBottom, 0.0, self.x_range, self.x_interval) #self.setAxisAutoScale(QwtPlot.yLeft,True) #self.setAxisScale(QwtPlot.yLeft,99.99,100.0,0.0005) self.setAxisScale(QwtPlot.yLeft, self.y_range_Lower, self.y_range_Upper, self.y_interval) self.setAxisLabelRotation(QwtPlot.xBottom, -45.0) self.x = np.arange( 0.0, self.x_range + 1, 0.25 ) #0.25 for ONE POINT, THIS SHOULD BE Align to the reading rate:250ms #self.z = np.zeros(len(self.x), np.float) list = [] for i in range(len(self.x)): list.append(0.0) self.z = np.array(list) rlist = [] for i in range(self.lenth): # 10s rlist.append(0.0) self.RateList = np.array(rlist) self.setTitle("UUT Reading Monitor - OutPort(%s)\r\n" % (self.unit)) #self.insertLegend(QwtLegend(), QwtPlot.RightLegend); self.curveL = QwtPlotCurve("UUT Reading") self.curveL.attach(self) pen = QPen(Qt.red) pen.setWidth(1.5) #pen.setWidth(1) self.curveL.setPen(pen) font = QFont() font.setFamily("Calibri") #,Consolas font.setPointSize(16) # show the latest reading. line and point value self.peakMarker = m = QwtPlotMarker() m.setLineStyle(QwtPlotMarker.HLine) m.setLabelAlignment(Qt.AlignLeft | Qt.AlignTop) m.setLinePen(QPen(Qt.blue, 1.5, Qt.DashDotLine)) text = QwtText('Reading: ----') text.setColor(Qt.red) text.setBackgroundBrush(QBrush(self.canvasBackground())) text.setFont(font) m.setLabel(text) # MarkPoint symbol m.setSymbol( QwtSymbol(QwtSymbol.Diamond, QBrush(Qt.blue), QPen(Qt.green), QSize(7, 7))) m.attach(self) # text marker , display slope rate self.txtMarker = m = QwtPlotMarker() m.setValue(self.x_range / 2, self.y_range_Upper - self.y_interval / 2) # show position m.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom) text = QwtText('Slope Rate: ----') text.setFont(font) text.setColor(Qt.white) text.setBackgroundBrush(QBrush(Qt.black)) text.setBorderPen(QPen(Qt.red, 2)) m.setLabel(text) m.attach(self) self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)") self.setAxisTitle(QwtPlot.yLeft, "UUT - Reading(%s)" % (self.unit)) self.replot() #self.startTimer(250)#ms# FOR GET READING #self.starttime = time.clock();#unit: s python2 self.starttime = time.time() # python3 self.idx = 0 self.readfmt = "%f" self.Saveinfo("Starting...")
def __init__(self, *args): QwtPlot.__init__(self, *args) self.setTitle('Frequency Response of a 2<sup>nd</sup>-order System') self.setCanvasBackground(Qt.darkBlue) # legend legend = QwtLegend() legend.setFrameStyle(QFrame.Box | QFrame.Sunken) self.insertLegend(legend, QwtPlot.BottomLegend) # grid self.grid = QwtPlotGrid() self.grid.enableXMin(True) self.grid.attach(self) # axes self.enableAxis(QwtPlot.yRight) self.setAxisTitle(QwtPlot.xBottom, '\u03c9/\u03c9<sub>0</sub>') self.setAxisTitle(QwtPlot.yLeft, 'Amplitude [dB]') self.setAxisTitle(QwtPlot.yRight, 'Phase [\u00b0]') self.setAxisMaxMajor(QwtPlot.xBottom, 6) self.setAxisMaxMinor(QwtPlot.xBottom, 10) self.setAxisScaleEngine(QwtPlot.xBottom, QwtLogScaleEngine()) # curves self.curve1 = QwtPlotCurve('Amplitude') self.curve1.setRenderHint(QwtPlotItem.RenderAntialiased) self.curve1.setPen(QPen(Qt.yellow)) self.curve1.setYAxis(QwtPlot.yLeft) self.curve1.attach(self) self.curve2 = QwtPlotCurve('Phase') self.curve2.setRenderHint(QwtPlotItem.RenderAntialiased) self.curve2.setPen(QPen(Qt.cyan)) self.curve2.setYAxis(QwtPlot.yRight) self.curve2.attach(self) # alias fn = self.fontInfo().family() # marker self.dB3Marker = m = QwtPlotMarker() m.setValue(0.0, 0.0) m.setLineStyle(QwtPlotMarker.VLine) m.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom) m.setLinePen(QPen(Qt.green, 2, Qt.DashDotLine)) text = QwtText('') text.setColor(Qt.green) text.setBackgroundBrush(Qt.red) text.setFont(QFont(fn, 12, QFont.Bold)) m.setLabel(text) m.attach(self) self.peakMarker = m = QwtPlotMarker() m.setLineStyle(QwtPlotMarker.HLine) m.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom) m.setLinePen(QPen(Qt.red, 2, Qt.DashDotLine)) text = QwtText('') text.setColor(Qt.red) text.setBackgroundBrush(QBrush(self.canvasBackground())) text.setFont(QFont(fn, 12, QFont.Bold)) m.setLabel(text) m.setSymbol( QwtSymbol(QwtSymbol.Diamond, QBrush(Qt.yellow), QPen(Qt.green), QSize(7, 7))) m.attach(self) # text marker m = QwtPlotMarker() m.setValue(0.1, -20.0) m.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom) text = QwtText('[1-(\u03c9/\u03c9<sub>0</sub>)<sup>2</sup>+2j\u03c9/Q]' '<sup>-1</sup>') text.setFont(QFont(fn, 12, QFont.Bold)) text.setColor(Qt.blue) text.setBackgroundBrush(QBrush(Qt.yellow)) text.setBorderPen(QPen(Qt.red, 2)) m.setLabel(text) m.attach(self) self.setDamp(0.01)
self.show() QApplication.processEvents() self.setCentralWidget(tabs) pts = 1000 for points, symbols in zip((pts / 10, pts / 10, pts, pts), (True, False) * 2): t0 = time.time() widget = CSWidget(points, symbols) symtext = "with%s symbols" % ("" if symbols else "out") title = '%d points, %s' % (points, symtext) tabs.addTab(widget, title) tabs.setCurrentWidget(widget) # Force widget to refresh (for test purpose only) QApplication.processEvents() time_str = "Elapsed time: %d ms" % ((time.time() - t0) * 1000) widget.text.setText(time_str) tabs.setCurrentIndex(0) if __name__ == '__main__': app = QApplication([]) for name in ('Calibri', 'Verdana', 'Arial'): if name in QFontDatabase().families(): app.setFont(QFont(name)) break demo = BMDemo(100000) app.exec_()
def __init__(self, *args): if len(args) == 0: title, parent = "", None elif len(args) == 1: if isinstance(args[0], QWidget) or args[0] is None: title = "" parent, = args else: title, = args parent = None elif len(args) == 2: title, parent = args else: raise TypeError("%s() takes 0, 1 or 2 argument(s) (%s given)"\ % (self.__class__.__name__, len(args))) QwtPlotDict.__init__(self) QFrame.__init__(self, parent) self.__layout_state = None self.__data = QwtPlot_PrivateData() from qwt.plot_layout import QwtPlotLayout self.__data.layout = QwtPlotLayout() self.__data.autoReplot = False self.setAutoReplot(True) # self.setPlotLayout(self.__data.layout) # title self.__data.titleLabel = QwtTextLabel(self) self.__data.titleLabel.setObjectName("QwtPlotTitle") self.__data.titleLabel.setFont(QFont(self.fontInfo().family(), 14, QFont.Bold)) text = QwtText(title) text.setRenderFlags(Qt.AlignCenter|Qt.TextWordWrap) self.__data.titleLabel.setText(text) # footer self.__data.footerLabel = QwtTextLabel(self) self.__data.footerLabel.setObjectName("QwtPlotFooter") footer = QwtText() footer.setRenderFlags(Qt.AlignCenter|Qt.TextWordWrap) self.__data.footerLabel.setText(footer) # legend self.__data.legend = None # axis self.__axisData = [] self.initAxesData() # canvas self.__data.canvas = QwtPlotCanvas(self) self.__data.canvas.setObjectName("QwtPlotCanvas") self.__data.canvas.installEventFilter(self) self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.resize(200, 200) focusChain = [self, self.__data.titleLabel, self.axisWidget(self.xTop), self.axisWidget(self.yLeft), self.__data.canvas, self.axisWidget(self.yRight), self.axisWidget(self.xBottom), self.__data.footerLabel] for idx in range(len(focusChain)-1): qwtSetTabOrder(focusChain[idx], focusChain[idx+1], False) qwtEnableLegendItems(self, True)