def tickLabel(self, font, value): lbl = self.__data.labelCache.get(value) if lbl is None: lbl = QwtText(self.label(value)) lbl.setRenderFlags(0) lbl.setLayoutAttribute(QwtText.MinimumLayout) lbl.textSize(font) self.__data.labelCache[value] = lbl return lbl
def tickLabel(self, font, value): """ Convert a value into its representing label and cache it. The conversion between value and label is called very often in the layout and painting code. Unfortunately the calculation of the label sizes might be slow (really slow for rich text in Qt4), so it's necessary to cache the labels. :param QFont font: Font :param float value: Value :return: Tick label """ lbl = self.__data.labelCache.get(value) if lbl is None: lbl = QwtText(self.label(value)) lbl.setRenderFlags(0) lbl.setLayoutAttribute(QwtText.MinimumLayout) lbl.textSize(font) self.__data.labelCache[value] = lbl return lbl
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)