def setTimeInterval(self, start_date, end_date): self.start = start_date self.end = end_date self.prepareGeometryChange() # self.interval = self.materializer.getTimeDifference(end_date, start_date) self.interval = end_date - start_date width = self.materializer.mapTimeRange(end_date, start_date) self.display_rect = qtc.QRectF(0, 0, width, self.ENTRY_HEIGHT) start_proxy = qtw.QGraphicsProxyWidget(self) start_label = qtw.QLabel() start_label.setAttribute(qtc.Qt.WA_TranslucentBackground) start_label.setFont(self.font) # start_label.setText('{0} • {1} • {2}'.format(*start_date)) start_label.setText(str(start_date)) start_label.adjustSize() start_proxy.setWidget(start_label) start_proxy.setPos( self.display_rect.bottomLeft().x() - start_label.width() / 2, self.display_rect.bottomLeft().y()) start_proxy.setVisible(False) self.year_labels.append(start_proxy) if self.start != self.end: end_proxy = qtw.QGraphicsProxyWidget(self) end_label = qtw.QLabel() end_label.setAttribute(qtc.Qt.WA_TranslucentBackground) end_label.setFont(self.font) # end_label.setText('{0} • {1} • {2}'.format(*end_date)) end_label.setText(str(end_date)) end_label.adjustSize() end_proxy.setWidget(end_label) end_proxy.setPos( self.display_rect.bottomRight().x() - end_label.width() / 2, self.display_rect.bottomRight().y()) end_proxy.setVisible(False) self.year_labels.append(end_proxy) if start_proxy.collidesWithItem(end_proxy): midline = self.display_rect.center().x() min_spacer = 10 max_spacer = 10 start_proxy.setPos(midline - min_spacer - start_label.width(), start_proxy.y()) end_proxy.setPos(midline + max_spacer, end_proxy.y()) else: self.year_labels.append(None) if self.font_metric.boundingRect( self._name).width() > self.display_rect.width(): self.pen = qtg.QPen(qtg.QColor('black'), 2) self.offset = (self.font_metric.boundingRect(self._name).width() - self.display_rect.width()) / 2 else: self.pen = qtg.QPen(qtg.QColor('white'), 2) self.offset = 0 self.setX(self.materializer.mapTime(start_date))
def __init__(self, name, rect): super().__init__() self.setZValue(1.0) self.setAcceptHoverEvents(True) self.setAcceptedMouseButtons(Qt.LeftButton) self.props = NodeProps() self.__rect = rect self.__view_rect = rect self.__transform = QtGui.QTransform() self.__drag_pos = None self.__box = QtWidgets.QGraphicsPathItem(self) pen = QtGui.QPen() pen.setColor(Qt.black) pen.setWidth(2) self.__box.setPen(pen) self.__box.setBrush(QtGui.QColor(200, 200, 200)) self.__box.setOpacity(0.7) self.__title = QtWidgets.QGraphicsSimpleTextItem(self) self.__title.setText(name) self.__body = NodeWidget(name) self.__body.setAutoFillBackground(False) self.__body.setAttribute(Qt.WA_NoSystemBackground, True) self.__body_proxy = QtWidgets.QGraphicsProxyWidget(self) self.__body_proxy.setWidget(self.__body)
def createProxyWidget(widget, minimum=None, preferred=None, maximum=None): w = QtWidgets.QGraphicsProxyWidget() w.setWidget(widget) if minimum is not None: w.setMinimumSize(minimum) if preferred is not None: w.setPreferredSize(preferred) if maximum is not None: w.setMaximumSize(maximum) return w
def CreatePicNode(self): # create my node nodeProxy = qw.QGraphicsProxyWidget() nodeProxy.setWidget(PicNode()) nodeProxy.setFlag(qw.QGraphicsItem.ItemStacksBehindParent, True) self._scene.addItem(nodeProxy) # create parent grabby item, sized a bit bigger than nodeProxy item1 = qw.QGraphicsRectItem(-5, -5, nodeProxy.rect().width() + 10, nodeProxy.rect().height() + 10) item1.setFlag(qw.QGraphicsItem.ItemIsMovable, True) item1.setFlag(qw.QGraphicsItem.ItemIsSelectable, True) self._scene.addItem(item1) # set parent nodeProxy.setParentItem(item1)
def createItem( minimum=QtCore.QSizeF(100.0, 100.0), preferred=QtCore.QSizeF(150.0, 100.0), maximum=QtCore.QSizeF(200.0, 100.0), name="0", ): w = QtWidgets.QGraphicsProxyWidget() w.setWidget(QtWidgets.QPushButton(name)) w.setData(0, name) w.setMinimumSize(minimum) w.setPreferredSize(preferred) w.setMaximumSize(maximum) w.setSizePolicy( QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred ) return w
def __init__(self, parent, match): super().__init__(parent) self.setBackgroundBrush(QtGui.QBrush(Qt.darkGray)) self.match = match self.combat = match.combat self.match.stateChanged.connect(self._refresh) fm = QtGui.QFontMetrics(self.font()) group = misc.VerticalGroup(alignment=Qt.AlignLeft) self.addItem(group) self.title1 = misc.Title() group.addItem(self.title1) self.enemies = stock.Stock(EnemyItem.size(fm)) group.addItem(self.enemies) self.title2 = misc.Title() group.addItem(self.title2) # Button bar buttonBar = QtWidgets.QGraphicsWidget() layout = QtWidgets.QGraphicsLinearLayout(Qt.Horizontal, buttonBar) self.okButton = QtWidgets.QPushButton(self.tr("Ok")) self.okButton.clicked.connect( lambda: self.match.combatNext()) # does not work without lambda! self.skipButton = QtWidgets.QPushButton(self.tr("Skip")) self.skipButton.clicked.connect( lambda: self.match.combatSkip()) # same for button in self.okButton, self.skipButton: proxy = QtWidgets.QGraphicsProxyWidget() proxy.setWidget(button) layout.addItem(proxy) group.addItem(buttonBar) layout.activate( ) # otherwise the following item will be positioned on top of the buttons self.stock = stock.Stock(EnemyItem.size(fm)) group.addItem(self.stock) self.combat.enemiesChanged.connect(self._refresh) self._refresh()
def main(): import sys app = QtWidgets.QApplication(sys.argv) label = QtWidgets.QLabel("Stack Overflow", alignment=QtCore.Qt.AlignCenter) graphicsview = QtWidgets.QGraphicsView() scene = QtWidgets.QGraphicsScene(graphicsview) graphicsview.setScene(scene) proxy = QtWidgets.QGraphicsProxyWidget() proxy.setWidget(label) proxy.setTransformOriginPoint(proxy.boundingRect().center()) scene.addItem(proxy) slider = QtWidgets.QSlider(minimum=0, maximum=359, orientation=QtCore.Qt.Horizontal) slider.valueChanged.connect(proxy.setRotation) matrix = QtGui.QTransform() matrix.rotate(180) label_text = QtWidgets.QLabel("{}°".format(slider.value()), alignment=QtCore.Qt.AlignCenter) #slider.valueChanged.connect( #lambda value: label_text.setText("{}°".format(slider.value())) #) slider.setValue(45) w = QtWidgets.QWidget() lay = QtWidgets.QVBoxLayout(w) lay.addWidget(graphicsview) lay.addWidget(slider) lay.addWidget(label_text) w.resize(640, 480) w.show() sys.exit(app.exec_())
def _adjust_positions(self): log.debug("Positioning player items") self.seat_item = Image.get("seat") self.seat_item.setPos(0, 0) seat_rect = self.seat_item.boundingRect() self.name_item.set_center(seat_rect.width() / 2, seat_rect.height() / 3) self.stack_item.set_center(seat_rect.width() / 2, seat_rect.height() * 2.2 / 3) self.action_widget_item = QtWidgets.QGraphicsProxyWidget() self.action_widget_item.setWidget(self.action_widget) self.action_widget_item.setFlag(self.ItemIgnoresTransformations) # TODO: really center widgets, need to hook to main window resize event w = self.action_widget.width() self.action_widget_item.setPos( (seat_rect.width() / 2) - (w / 2), seat_rect.height() ) for c in self.card_items: self.addToGroup(c) self.action_widget_item.setZValue(10)
def setSetValues(self, value): self._set_values = value self._grid = QtWidgets.QGridLayout() self._grid.setVerticalSpacing(2) self._wid = QtWidgets.QWidget() self._wid.setLayout(self._grid) prox = QtWidgets.QGraphicsProxyWidget(self) prox.setWidget(self._wid) prox.setPos(15, 40) #self.boundingRect().height()/2) i = 0 for node, setpoint in self._set_values: name = node.name off_name = node.offName on_name = node.onName label = QtWidgets.QLabel(name) combo = QtWidgets.QComboBox() combo.addItems(["", str(off_name), str(on_name)]) if setpoint == 0: combo.setCurrentIndex(1) elif setpoint == 1: combo.setCurrentIndex(2) else: combo.setCurrentIndex(0) self._grid.addWidget(label, i, 0) self._grid.addWidget(combo, i, 1) self._grid_items.append((node, combo)) i += 1 self.height = 80 + i * 25 #FIXME cant figure out the size hint for node, combo in self._grid_items: combo.currentIndexChanged.connect(self.comboChanged)
def __init__(self, *, node: music.BaseNode, icon: Optional[QtSvg.QSvgRenderer] = None, **kwargs: Any) -> None: super().__init__(**kwargs) self.setZValue(1.0) self.setAcceptHoverEvents(True) self.setAcceptedMouseButtons(Qt.LeftButton) self.props = NodeProps() self.__session_prefix = 'node/%016x/' % node.id self.__listeners = core.ListenerList() self.add_cleanup_function(self.__listeners.cleanup) self.__node = node self.__window = None # type: QtWidgets.QWidget self.__box = Box(self) if icon is not None: self.__icon = NodeIcon(icon, self) else: self.__icon = None self.__ports = {} # type: Dict[str, Port] for port_desc in self.__node.description.ports: port = Port(port_desc, self) self.__ports[port_desc.name] = port self.__title = Title(self.__node.name, self) self.__title_edit = QtWidgets.QLineEdit() self.__title_edit.editingFinished.connect(self.__renameNodeFinished) self.__title_edit_proxy = QtWidgets.QGraphicsProxyWidget(self) self.__title_edit_proxy.setWidget(self.__title_edit) self.__title_widgets_proxy = None self.__title_widgets_container = None title_widgets = list(self.titleWidgets()) if title_widgets: self.__title_widgets_container = QtWidgets.QWidget() self.__title_widgets_container.setAutoFillBackground(False) self.__title_widgets_container.setAttribute( Qt.WA_NoSystemBackground, True) layout = QtWidgets.QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(1) for widget in title_widgets: layout.addWidget(widget) self.__title_widgets_container.setLayout(layout) self.__title_widgets_proxy = QtWidgets.QGraphicsProxyWidget(self) self.__title_widgets_proxy.setWidget( self.__title_widgets_container) self.__body_proxy = None # type: QtWidgets.QGraphicsProxyWidget self.__body = self.createBodyWidget() if self.__body is not None: self.__body.setAutoFillBackground(False) self.__body.setAttribute(Qt.WA_NoSystemBackground, True) self.__body_proxy = QtWidgets.QGraphicsProxyWidget(self) self.__body_proxy.setWidget(self.__body) self.__transform = QtGui.QTransform() self.__canvas_rect = self.__transform.mapRect(self.contentRect()) self.__selected = False self.__hovered = False self.__rename_node = False self.__drag_rect = QtCore.QRectF() self.__listeners.add(self.__node.name_changed.add(self.__nameChanged)) self.__listeners.add( self.__node.graph_pos_changed.add(self.__graphRectChanged)) self.__listeners.add( self.__node.graph_size_changed.add(self.__graphRectChanged)) self.__listeners.add( self.__node.graph_color_changed.add( lambda *_: self.__updateState())) self.__listeners.add( self.__node.port_properties_changed.add( lambda *_: self.__layout())) self.__listeners.add( self.__node.description_changed.add( lambda *_: self.__descriptionChanged())) self.__state = None # type: audioproc.NodeStateChange.State self.__listeners.add( self.audioproc_client.node_state_changed.add( '%08x' % self.__node.id, self.__stateChanged)) self.__updateState()
def __init__(self, event_dict, parent=None): super(EntryView, self).__init__(parent) self.setAttribute(qtc.Qt.WA_DeleteOnClose) self.setFlags(qtw.QGraphicsItem.ItemIsMovable | qtw.QGraphicsItem.ItemIsSelectable) self.setAcceptHoverEvents(True) self.setCursor(qtc.Qt.OpenHandCursor) self.setScale(1.4) self._event = event_dict self._id = self._event['event_id'] self.setObjectName('view{}'.format(self._id)) self.brush = qtg.QBrush( qtg.QColor('#c9cdd4')) # make dependent upon gender? kingdom? self.translucent_effect = qtw.QGraphicsOpacityEffect(self) self.translucent_effect.setOpacity(0.8) self.setGraphicsEffect(self.translucent_effect) self.translucent_effect.setEnabled(False) self.setSizePolicy(qtw.QSizePolicy.Preferred, qtw.QSizePolicy.Preferred) self.display_widgets = qtw.QGraphicsItemGroup(self) # Set layout layout = qtw.QGraphicsLinearLayout(qtc.Qt.Vertical) label_style = """ QLabel { background-color: #e3ddcc; border-radius: 5px; border-color: gray; padding: 4px; font: 24px; }""" # Create and add label widgets self.name_label = qtw.QGraphicsProxyWidget(self) self.name_label.setWidget(EntryViewLabel()) self.name_label.widget().setStyleSheet("""QLabel { background-color: rgba(255, 255, 255, 0); border-radius: 5px; border-color: gray; padding: 4px; font: 36px 'Didot'; }""") self.name_label.widget().setAlignment(qtc.Qt.AlignHCenter | qtc.Qt.AlignVCenter) self.name_label.setAcceptHoverEvents(False) layout.addItem(self.name_label) self.start_label = qtw.QGraphicsProxyWidget(self) self.start_label.setWidget(EntryViewLabel()) self.start_label.widget().setStyleSheet(label_style) self.start_label.setAcceptHoverEvents(False) layout.addItem(self.start_label) self.end_label = qtw.QGraphicsProxyWidget(self) self.end_label.setWidget(EntryViewLabel()) self.end_label.widget().setStyleSheet(label_style) self.end_label.setAcceptHoverEvents(False) layout.addItem(self.end_label) self.loc_label = qtw.QGraphicsProxyWidget(self) self.loc_label.setWidget(EntryViewLabel()) self.loc_label.widget().setStyleSheet(label_style) self.loc_label.setAcceptHoverEvents(False) layout.addItem(self.loc_label) self.updateView() self.cancel_btn = qtw.QGraphicsProxyWidget(self) self.cancel_btn.setWidget(qtw.QPushButton('Cancel', clicked=self.close)) self.cancel_btn.widget().setStyleSheet(""" QPushButton { border: 1px solid black; border-style: outset; border-radius: 2px; color: black; font: 24px; font-family: Baskerville; } QPushButton:pressed { background-color: rgba(255, 255, 255, 70); border-style: inset; }""") layout.addItem(self.cancel_btn) layout.setSpacing(16) self.setLayout(layout)
def setTimeInterval(self, start_date, end_date): self.start = start_date self.end = end_date # self.interval = self.materializer.getTimeDifference(end_date, start_date) self.interval = self.end - self.start width = self.materializer.mapTimeRange(self.end, self.start) self.display_rect = qtc.QRectF(0, 0, width, self.ENTRY_HEIGHT) start_proxy = qtw.QGraphicsProxyWidget(self) self.name_proxy = qtw.QGraphicsProxyWidget(self) start_label = qtw.QLabel() name_label = qtw.QLabel() start_label.setAttribute(qtc.Qt.WA_TranslucentBackground) name_label.setAttribute(qtc.Qt.WA_TranslucentBackground) start_label.setFont(self.font) name_label.setFont(self.name_font) # start_label.setText('{0} • {1} • {2}'.format(*start_date)) start_label.setText(str(start_date)) name_label.setText(self._name) start_label.adjustSize() name_label.adjustSize() start_proxy.setWidget(start_label) self.name_proxy.setWidget(name_label) start_proxy.setPos( self.display_rect.topLeft().x() - start_label.width() / 2, self.display_rect.topLeft().y() - start_label.height()) self.name_proxy.setPos( self.display_rect.center().x() - name_label.width() / 2, self.display_rect.top() - name_label.height()) start_proxy.setVisible(False) self.year_labels.append(start_proxy) if self.start != self.end: end_proxy = qtw.QGraphicsProxyWidget(self) end_label = qtw.QLabel() end_label.setAttribute(qtc.Qt.WA_TranslucentBackground) end_label.setFont(self.font) # end_label.setText('{0} • {1} • {2}'.format(*end_date)) end_label.setText(str(end_date)) end_label.adjustSize() end_proxy.setWidget(end_label) end_proxy.setPos( self.display_rect.topRight().x() - end_label.width() / 2, self.display_rect.topRight().y() - end_label.height()) self.year_labels.append(end_proxy) end_proxy.setVisible(False) if start_proxy.collidesWithItem(end_proxy): del end_proxy else: self.year_labels.append(None) if start_proxy.collidesWithItem(self.name_proxy): start_proxy.setPos( start_proxy.x(), start_proxy.y() - self.name_proxy.preferredHeight()) self.buildShape() self.setX(self.materializer.mapTime(start_date))
def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.setupUi(self) self.n = 0 self.puerto = "" self.baudrate = 9600 self.cant_acel1 = 100 self.cant_acel2 = 100 self.cant_vel = 400 self.cant_current = 400 self.acel_x1_all = NewList(self.cant_acel1) self.acel_y1_all = NewList(self.cant_acel1) self.acel_z1_all = NewList(self.cant_acel1) self.acel_x2_all = NewList(self.cant_acel2) self.acel_y2_all = NewList(self.cant_acel2) self.acel_z2_all = NewList(self.cant_acel2) self.velocidad_all = NewList(self.cant_vel) self.corriente_all = NewList(self.cant_current) self.pg_window_acel1 = pg.GraphicsWindow() self.pg_window_acel2 = pg.GraphicsWindow() self.pg_window_vel = pg.GraphicsWindow() self.pg_gen_acel1 = self.pg_window_acel1.addPlot() self.pg_gen_acel1.addLegend() self.pg_plot_acel1_x = self.pg_gen_acel1.plot(name="eje x") self.pg_plot_acel1_y = self.pg_gen_acel1.plot(name="eje y") self.pg_plot_acel1_z = self.pg_gen_acel1.plot(name="eje z") self.pg_gen_acel2 = self.pg_window_acel2.addPlot() self.pg_gen_acel2.addLegend() self.pg_plot_acel2_x = self.pg_gen_acel2.plot(name="eje x") self.pg_plot_acel2_y = self.pg_gen_acel2.plot(name="eje y") self.pg_plot_acel2_z = self.pg_gen_acel2.plot(name="eje z") self.pg_gen_vel = self.pg_window_vel.addPlot() self.pg_plot_vel = self.pg_gen_vel.plot() self.pg_plot_current = self.pg_gen_vel.plot() self.qt_aceleracion_layout.addWidget(self.pg_window_acel1) self.qt_velocidad_layout.addWidget(self.pg_window_vel) self.qt_aceleracion2_layout.addWidget(self.pg_window_acel2) self.qt_conectar_button.clicked.connect(self.conectar) self.qt_parar_button.clicked.connect(self.parar) self.qt_guardar_button.clicked.connect(self.guardar) self.qt_limpiar_button.clicked.connect(self.limpiar) # Inclinacion self.label = QtWidgets.QLabel("<---------------->", alignment=QtCore.Qt.AlignCenter) graphicsview = QtWidgets.QGraphicsView() scene = QtWidgets.QGraphicsScene(graphicsview) graphicsview.setScene(scene) self.proxy = QtWidgets.QGraphicsProxyWidget() self.proxy.setWidget(self.label) self.proxy.setTransformOriginPoint(self.proxy.boundingRect().center()) scene.addItem(self.proxy) self.qt_inclinacion_layout.addWidget(graphicsview)
def __init__(self, element, parent=None): super().__init__(parent=parent) w = element() self.container_widget = QtWidgets.QWidget() self.event_filter = EventFilter() self.container_widget.installEventFilter(self.event_filter) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) w.setSizePolicy(sizePolicy) layout = QtWidgets.QHBoxLayout(self.container_widget) layout.addWidget(w) layout.setContentsMargins(0, 0, 0, 0) self.container_widget.setLayout(layout) self.proxy = QtWidgets.QGraphicsProxyWidget() self.proxy.setWidget(self.container_widget) # self.proxy.setGeometry(QtCore.QRectF(0, 0, 600, 600)) self.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0))) self.setBrush(QtGui.QBrush(QtGui.QColor(200, 200, 200))) self.setFlag(self.ItemIsMovable, True) self.setFlag(self.ItemSendsGeometryChanges, True) self.setFlag(self.ItemIsSelectable, True) x, y, w, h = self.container_widget.x(), self.container_widget.y( ), self.container_widget.width(), self.container_widget.height() rect = [ x - self.border, y - self.border - self.header_height, w + 2 * self.border, self.header_height, ] self.setRect(*rect) self.header_text = QtWidgets.QGraphicsTextItem(element.name) self.header_text.setPos(-5, -24) # font = QtGui.QFont('Consolas', 8) font = QtGui.QFont() font = QtGui.QFont(font.defaultFamily(), 9) color = QtGui.QColor(0, 0, 0) self.header_text.setFont(font) self.header_text.setDefaultTextColor(color) self.container = QtWidgets.QGraphicsRectItem() self.container.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0))) self.container.setBrush(QtGui.QBrush(QtGui.QColor(100, 100, 100))) rect = [ x - self.border, y - self.border, w + 2 * self.border, h + 2 * self.border, ] self.container.setRect(*rect) self.resizer = ElementResizerItem(self) crect = self.container.rect() cx, cy, ch, cw = crect.x(), crect.y(), crect.height(), crect.width() rect = [ cx + cw - self.resizer_size / 2, cy + ch - self.resizer_size / 2, self.resizer_size, self.resizer_size, ] self.resizer.setRect(*rect) self.resizer.setParentItem(self.container) self.proxy.setParentItem(self.container) self.container.setParentItem(self) self.header_text.setParentItem(self) return