def __init__(self, name, position, players, parent): super().__init__(parent=parent) self.name = name self.position = position self.tokens = [] self.owner = False self.layout = QGraphicsLinearLayout() self.token_layout = QGraphicsGridLayout() self.token_layout.setSpacing(0.5) self.name_on_tile = QGraphicsWidget() self.info = QGraphicsWidget() self.layout.setOrientation(Qt.Vertical) self.setContentsMargins(75, 0, 90, 0) property_name = QGraphicsTextItem(self.name, parent=self.name_on_tile) if name in parent.properties: self.real_pos = parent.board_positions[parent.properties.index(name)] if self.real_pos in mp_core.PROPERTIES: self.price = mp_core.PROPERTIES[self.real_pos][name]["Price"] self.rent = mp_core.PROPERTIES[self.real_pos][name]["Rent"] money_info = QGraphicsTextItem(f"Price: {self.price}", parent=self.info) elif self.real_pos in mp_core.SPECIAL_CASES: tile = list(mp_core.SPECIAL_CASES[self.real_pos].keys())[0] if tile == "Start": money_start = QGraphicsTextItem("Free monay: 200", parent=self.info) for player in players: token = Token(player) token.set_tile(tile) self.tokens.append(token) self.display_game_pieces() elif tile in ["Income Tax", "Super Tax"]: money = mp_core.SPECIAL_CASES[self.real_pos][tile] money_tax = QGraphicsTextItem(f"Tax: -{money}", parent=self.info) self.layout.addItem(self.name_on_tile) self.layout.addItem(self.info) self.layout.addItem(self.token_layout) self.setLayout(self.layout) self.layout.setAlignment(self.layout, Qt.AlignCenter)
def __init__(self): super().__init__() self.setWindowTitle('loading_gif') self.resize(250, 120) self.scene = QGraphicsScene() self.setScene(self.scene) main_layout = QGraphicsLinearLayout(Qt.Horizontal) form = QGraphicsWidget() form.setLayout(main_layout) self.scene.addItem(form) for i in range(3): movie = QMovie("loading.gif") label_loading = QLabel() label_loading.setMovie(movie) movie.start() label_loading.setFrameStyle(QLabel.Box) label_loading.setAttribute(Qt.WA_OpaquePaintEvent) proxy_item = self.scene.addWidget(label_loading) main_layout.addItem(proxy_item)
def setupSceneItems(self): if Colors.showFps: self.fpsLabel = DemoTextItem("FPS: --", Colors.buttonFont(), Qt.white, -1, None, DemoTextItem.DYNAMIC_TEXT) self.fpsLabel.setZValue(1000) self.fpsLabel.setPos( Colors.stageStartX, 600 - QFontMetricsF(Colors.buttonFont()).height() - 5) self.mainSceneRoot = QGraphicsWidget() self.scene.addItem(self.mainSceneRoot) self.companyLogo = ImageItem( QImage(self.imagesDir + '/trolltech-logo.png'), 1000, 1000, None, True, 0.5) self.qtLogo = ImageItem(QImage(self.imagesDir + '/qtlogo_small.png'), 1000, 1000, None, True, 0.5) self.companyLogo.setZValue(100) self.qtLogo.setZValue(100) self.pausedLabel = DemoTextItem("PAUSED", Colors.buttonFont(), Qt.white, -1, None) self.pausedLabel.setZValue(100) fm = QFontMetricsF(Colors.buttonFont()) self.pausedLabel.setPos(Colors.stageWidth - fm.width("PAUSED"), 590 - fm.height()) self.pausedLabel.setRecursiveVisible(False)
def __init__(self): super().__init__() self.scene = QGraphicsScene() self.scene.setSceneRect(0, 0, 200, 200) self.view = QGraphicsView() self.view.setRenderHint(QPainter.HighQualityAntialiasing) self.view.setAlignment(Qt.AlignLeft | Qt.AlignTop) self.view.setScene(self.scene) scene_layout = QGraphicsLinearLayout(Qt.Horizontal) form = QGraphicsWidget() form.setLayout(scene_layout) self.scene.addItem(form) self.main_layout = QHBoxLayout() self.main_layout.addWidget(self.view) self.setLayout(self.main_layout) self.rb0 = QPushButton("Hello") proxy_rb0 = self.scene.addWidget(self.rb0) scene_layout.addItem(proxy_rb0) self.rb1 = QPushButton("Hello") proxy_rb1 = self.scene.addWidget(self.rb1) proxy_rb1.setRotation(90) scene_layout.addItem(proxy_rb1) self.rb2 = QPushButton("Hello") proxy_rb2 = self.scene.addWidget(self.rb2) proxy_rb2.setRotation(180) scene_layout.addItem(proxy_rb2) self.rb3 = QPushButton("Hello") proxy_rb3 = self.scene.addWidget(self.rb3) proxy_rb3.setRotation(-166) scene_layout.addItem(proxy_rb3)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) width = Settings.NUM_BLOCKS_X * (Settings.WIDTH + 1) height = Settings.NUM_BLOCKS_Y * (Settings.HEIGHT + 1) self.setSceneRect(0, 0, height, width) self.setItemIndexMethod(QtWidgets.QGraphicsScene.NoIndex) layout = QGraphicsGridLayout() layout.setVerticalSpacing(0) layout.setHorizontalSpacing(0) form = QGraphicsWidget() form.setLayout(layout) for i in range(Settings.NUM_BLOCKS_X): layout.setRowSpacing(i, 0) layout.setRowMaximumHeight(i, Settings.HEIGHT) for j in range(Settings.NUM_BLOCKS_Y): layout.setColumnSpacing(j, 0) layout.setColumnMaximumWidth(j, Settings.WIDTH) if j - i == 1: rect = RectangleWidget(QRectF(0, 0, Settings.WIDTH, Settings.HEIGHT), path=True) elif j - i == 3: rect = RectangleWidget(QRectF(0, 0, Settings.WIDTH, Settings.HEIGHT), item=True) else: rect = RectangleWidget( QRectF(0, 0, Settings.WIDTH, Settings.HEIGHT)) layout.addItem(rect, i, j) self.addItem(form)
def __init__(self): super().__init__() # Set up the Scene to manage the GraphicItems self.scene = QGraphicsScene(0, 0, 500, 600, self) self.setScene(self.scene) self.setSceneRect(self.scene.sceneRect()) # Add the Boards to the form with a vertical layout self.form = QGraphicsWidget() self.layout = QGraphicsLinearLayout(Qt.Vertical) self.gameboard = board.GameBoard(400, 400) self.menuboard = board.MenuBoard(400, 80) self.layout.addItem(self.gameboard) self.layout.addItem(self.menuboard) self.layout.setSpacing(50) self.layout.setContentsMargins(50, 50, 50, 0) self.form.setLayout(self.layout) self.scene.addItem(self.form) # Setting the view self.setBackgroundBrush(QBrush(Qt.black)) self.setRenderHint(QPainter.Antialiasing) self.fitInView(self.scene.sceneRect(), Qt.KeepAspectRatio) self.show() # Cross-Board signal connections self.gameboard.gridDrawn.connect( lambda: self.menuboard.show_children(True)) self.gameboard.newGameSelected.connect( self.menuboard.set_difficulty_text) self.gameboard.sudokuDone.connect(self.menuboard.finish_the_game) self.menuboard.diff_display.notFocus.connect( self.gameboard.game_refocus) self.menuboard.diff_display.difficultySelected.connect( self.gameboard.new_game)
minSize = QSizeF(30, 100) prefSize = QSizeF(210, 100) maxSize = QSizeF(300, 100) a = createItem(minSize, prefSize, maxSize, "A") b = createItem(minSize, prefSize, maxSize, "B") c = createItem(minSize, prefSize, maxSize, "C") d = createItem(minSize, prefSize, maxSize, "D") e = createItem(minSize, prefSize, maxSize, "E") f = createItem(QSizeF(30, 50), QSizeF(150, 50), maxSize, "F") g = createItem(QSizeF(30, 50), QSizeF(30, 100), maxSize, "G") l = QGraphicsAnchorLayout() l.setSpacing(0) w = QGraphicsWidget(None, Qt.Window) w.setPos(20, 20) w.setLayout(l) # Vertical. l.addAnchor(a, Qt.AnchorTop, l, Qt.AnchorTop) l.addAnchor(b, Qt.AnchorTop, l, Qt.AnchorTop) l.addAnchor(c, Qt.AnchorTop, a, Qt.AnchorBottom) l.addAnchor(c, Qt.AnchorTop, b, Qt.AnchorBottom) l.addAnchor(c, Qt.AnchorBottom, d, Qt.AnchorTop) l.addAnchor(c, Qt.AnchorBottom, e, Qt.AnchorTop) l.addAnchor(d, Qt.AnchorBottom, l, Qt.AnchorBottom) l.addAnchor(e, Qt.AnchorBottom, l, Qt.AnchorBottom)
box = QGroupBox() box.setFlat(True) box.setTitle("Options") layout2 = QVBoxLayout() box.setLayout(layout2) layout2.addWidget(QRadioButton("Herring")) layout2.addWidget(QRadioButton("Blue Parrot")) layout2.addWidget(QRadioButton("Petunias")) layout2.addStretch() boxProxy = QGraphicsProxyWidget() boxProxy.setWidget(box) # Parent widget. widget = QGraphicsWidget() layout = QGraphicsLinearLayout(Qt.Vertical, widget) layout.addItem(editProxy) layout.addItem(buttonProxy) widget.setLayout(layout) p1 = Pixmap(QPixmap(':/digikam.png')) p2 = Pixmap(QPixmap(':/akregator.png')) p3 = Pixmap(QPixmap(':/accessories-dictionary.png')) p4 = Pixmap(QPixmap(':/k3b.png')) p5 = Pixmap(QPixmap(':/help-browser.png')) p6 = Pixmap(QPixmap(':/kchart.png')) scene = QGraphicsScene(0, 0, 400, 300) scene.setBackgroundBrush(scene.palette().window()) scene.addItem(widget)
def __init__(self, dither, detectors, *args): super().__init__(*args) self._enabled_detectors = detectors self._boxes = { } # this will be of the form {detector_number: DetectorBox} self.gv_layout = QGraphicsGridLayout() self.gv_layout.setSpacing(0) min_length = DetectorBox.length * 4 + 6 self._min_length = min_length self._dither = dither self.gv_layout.setMinimumSize(min_length, min_length) self.gv_layout.setMaximumSize(min_length, min_length) self.gv_layout.setContentsMargins(0, 0, 0, 0) self.setMinimumWidth(min_length) self.setMinimumHeight(min_length) self.setMaximumWidth(min_length + 20) self.setMaximumHeight(min_length + 20) self._init_boxes() gv_widget = QGraphicsWidget() gv_widget.setLayout(self.gv_layout) gv_widget.setContentsMargins(0, 0, 0, 0) scene = QGraphicsScene() scene.addItem(gv_widget) scene.setSceneRect(0, 0, min_length, min_length) view = QGraphicsView() view.setMouseTracking(True) view.setViewportMargins(0, 0, 0, 0) view.setGeometry(0, 0, min_length, min_length) view.setStyleSheet("border: 0px; margin: 0px; padding: 0px;") view.setScene(scene) view.setTransform(flip_vertical, True) layout = QVBoxLayout() layout.addWidget(view) self.setLayout(layout)
def __updateState(self): """ Update the widget with the new source/sink node signal descriptions. """ widget = QGraphicsWidget() widget.setLayout(QGraphicsGridLayout()) # Space between left and right anchors widget.layout().setHorizontalSpacing(50) left_node = EditLinksNode(self, direction=Qt.LeftToRight, node=self.source) left_node.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) right_node = EditLinksNode(self, direction=Qt.RightToLeft, node=self.sink) right_node.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) left_node.setMinimumWidth(150) right_node.setMinimumWidth(150) widget.layout().addItem( left_node, 0, 0, ) widget.layout().addItem( right_node, 0, 1, ) title_template = "<center><b>{0}<b></center>" left_title = GraphicsTextWidget(self) left_title.setHtml(title_template.format(escape(self.source.title))) left_title.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) right_title = GraphicsTextWidget(self) right_title.setHtml(title_template.format(escape(self.sink.title))) right_title.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) widget.layout().addItem(left_title, 1, 0, alignment=Qt.AlignHCenter | Qt.AlignTop) widget.layout().addItem(right_title, 1, 1, alignment=Qt.AlignHCenter | Qt.AlignTop) widget.setParentItem(self) max_w = max( left_node.sizeHint(Qt.PreferredSize).width(), right_node.sizeHint(Qt.PreferredSize).width()) # fix same size left_node.setMinimumWidth(max_w) right_node.setMinimumWidth(max_w) left_title.setMinimumWidth(max_w) right_title.setMinimumWidth(max_w) self.layout().addItem(widget) self.layout().activate() self.sourceNodeWidget = left_node self.sinkNodeWidget = right_node self.sourceNodeTitle = left_title self.sinkNodeTitle = right_title
def __init__( self, name, board_pos, price, rent, mortgage, players, color, group_name, number_in_group, house_price, parent, ): super().__init__(parent=parent) self.name = name self.board_pos = board_pos self.price = price self.rent = rent self.mortgage = mortgage self.color = color self.group_name = group_name self.number_in_group = number_in_group self.tokens = [] self.owner = False self.house_price = house_price self.nb_houses = 0 self.hotel = False self.layout = QGraphicsLinearLayout() self.token_layout = QGraphicsGridLayout() self.color_property = QGraphicsWidget() self.name_on_tile = QGraphicsWidget() self.info = QGraphicsWidget() self.layout.setOrientation(Qt.Vertical) property_name = QGraphicsTextItem(self.name, parent=self.name_on_tile) if name in parent.properties: if self.board_pos in core.PROPERTIES: money_info = QGraphicsTextItem(f"Price: {self.price}", parent=self.info) self.color_rect = self.color_tile(color) elif self.board_pos in core.SPECIAL_CASES: if name == "Start": money_start = QGraphicsTextItem( f"Free monay: {self.price}", parent=self.info) for player, color in players.items(): token = Token.Token(player, color) token.set_tile(self) self.tokens.append(token) self.display_game_pieces() elif name in ["Income Tax", "Super Tax"]: money_tax = QGraphicsTextItem(f"Tax: -{self.price}", parent=self.info) self.token_layout.setColumnMaximumWidth(0, 22) self.token_layout.setColumnMaximumWidth(1, 22) self.token_layout.setColumnMaximumWidth(2, 22) self.token_layout.setSpacing(1) self.layout.addItem(self.color_property) self.layout.addItem(self.name_on_tile) self.layout.addItem(self.info) self.layout.addItem(self.token_layout) self.setLayout(self.layout) self.setContentsMargins(0, 0, 100, 0)