def test_construct(qtbot): """ Test the construction of the widget. Expectations: Default values are correctly assigned. Parameters ---------- qtbot : fixture Window for widget testing """ pydm_slider = PyDMSlider() qtbot.addWidget(pydm_slider) assert pydm_slider.alarmSensitiveContent is True assert pydm_slider.alarmSensitiveBorder is False assert pydm_slider._show_limit_labels is True assert pydm_slider._show_value_label is True assert pydm_slider._user_defined_limits is False assert pydm_slider._needs_limit_info is True assert pydm_slider._minimum is None assert pydm_slider._maximum is None assert pydm_slider._user_minimum == -10.0 assert pydm_slider._user_maximum == 10.0 assert pydm_slider._num_steps == 101 assert pydm_slider.orientation == Qt.Horizontal assert pydm_slider.isEnabled() is False assert type(pydm_slider.low_lim_label) == QLabel assert pydm_slider.low_lim_label.sizePolicy() == QSizePolicy( QSizePolicy.Maximum, QSizePolicy.Fixed) assert pydm_slider.low_lim_label.alignment() == Qt.Alignment( Qt.AlignLeft | Qt.AlignTrailing | Qt.AlignVCenter) assert type(pydm_slider.high_lim_label) == QLabel assert pydm_slider.high_lim_label.sizePolicy() == QSizePolicy( QSizePolicy.Maximum, QSizePolicy.Fixed) assert pydm_slider.high_lim_label.alignment() == Qt.Alignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter) assert type(pydm_slider._slider) == QSlider assert pydm_slider._slider.orientation() == Qt.Orientation(Qt.Horizontal) assert pydm_slider._slider_position_to_value_map is None assert pydm_slider._mute_internal_slider_changes is False assert pydm_slider._orientation == Qt.Horizontal
def anchor(self, widget, left=True, right=True, top=True, bottom=True): '''anchor the widget. Depending on the anchors, widget will be left-, right-, center-aligned or stretched. ''' align = { (False, False): Qt.AlignHCenter, (True, False): Qt.AlignLeft, (False, True): Qt.AlignRight, (True, True): Qt.Alignment() }[(left, right)] widget.parent().layout().setAlignment(widget, align)
def createEditor( self, parent: QWidget, option: QStyleOptionViewItem, index: QtCore.QModelIndex, ) -> QWidget: """User has double clicked on layer name.""" # necessary for geometry, otherwise editor takes up full width. self.get_layer_icon(option, index) editor = super().createEditor(parent, option, index) # make sure editor has same alignment as the display name editor.setAlignment(Qt.Alignment(index.data(Qt.TextAlignmentRole))) return editor
def drawLabel(self, painter, canvasRect, pos): """ Align and draw the text label of the marker :param QPainter painter: Painter :param QRectF canvasRect: Contents rectangle of the canvas in painter coordinates :param QPointF pos: Position of the marker, translated into widget coordinates .. seealso:: :py:meth:`drawLabel()`, :py:meth:`qwt.symbol.QwtSymbol.drawSymbol()` """ if self.__data.label.isEmpty(): return align = Qt.Alignment(self.__data.labelAlignment) alignPos = QPointF(pos) symbolOff = QSizeF(0, 0) if self.__data.style == QwtPlotMarker.VLine: # In VLine-style the y-position is pointless and # the alignment flags are relative to the canvas if bool(self.__data.labelAlignment & Qt.AlignTop): alignPos.setY(canvasRect.top()) align &= ~Qt.AlignTop align |= Qt.AlignBottom elif bool(self.__data.labelAlignment & Qt.AlignBottom): # In HLine-style the x-position is pointless and # the alignment flags are relative to the canvas alignPos.setY(canvasRect.bottom() - 1) align &= ~Qt.AlignBottom align |= Qt.AlignTop else: alignPos.setY(canvasRect.center().y()) elif self.__data.style == QwtPlotMarker.HLine: if bool(self.__data.labelAlignment & Qt.AlignLeft): alignPos.setX(canvasRect.left()) align &= ~Qt.AlignLeft align |= Qt.AlignRight elif bool(self.__data.labelAlignment & Qt.AlignRight): alignPos.setX(canvasRect.right() - 1) align &= ~Qt.AlignRight align |= Qt.AlignLeft else: alignPos.setX(canvasRect.center().x()) else: if self.__data.symbol and self.__data.symbol.style( ) != QwtSymbol.NoSymbol: symbolOff = self.__data.symbol.size() + QSizeF(1, 1) symbolOff /= 2 pw2 = self.__data.pen.widthF() / 2.0 if pw2 == 0.0: pw2 = 0.5 spacing = self.__data.spacing xOff = max([pw2, symbolOff.width()]) yOff = max([pw2, symbolOff.height()]) textSize = self.__data.label.textSize(painter.font()) if align & Qt.AlignLeft: alignPos.setX(alignPos.x() - (xOff + spacing)) if self.__data.labelOrientation == Qt.Vertical: alignPos.setX(alignPos.x() - textSize.height()) else: alignPos.setX(alignPos.x() - textSize.width()) elif align & Qt.AlignRight: alignPos.setX(alignPos.x() + xOff + spacing) else: if self.__data.labelOrientation == Qt.Vertical: alignPos.setX(alignPos.x() - textSize.height() / 2) else: alignPos.setX(alignPos.x() - textSize.width() / 2) if align & Qt.AlignTop: alignPos.setY(alignPos.y() - (yOff + spacing)) if self.__data.labelOrientation != Qt.Vertical: alignPos.setY(alignPos.y() - textSize.height()) elif align & Qt.AlignBottom: alignPos.setY(alignPos.y() + yOff + spacing) if self.__data.labelOrientation == Qt.Vertical: alignPos.setY(alignPos.y() + textSize.width()) else: if self.__data.labelOrientation == Qt.Vertical: alignPos.setY(alignPos.y() + textSize.width() / 2) else: alignPos.setY(alignPos.y() - textSize.height() / 2) painter.translate(alignPos.x(), alignPos.y()) if self.__data.labelOrientation == Qt.Vertical: painter.rotate(-90.0) textRect = QRectF(0, 0, textSize.width(), textSize.height()) self.__data.label.draw(painter, textRect)
def setAlignment(self, value): self._alignment = Qt.Alignment(value) self.update()
def setAlignment(self, value): self._alignment = Qt.Alignment(value) self.placeLed()
def addWidget(self, widget, stretch=0, alignment=None): "Append widget to layout, make its width fixed" # widget.setMinimumSize(widget.minimumSizeHint()) # FIXME: super().insertWidget(self.count(), widget, stretch, alignment or Qt.Alignment(0))