1

2 つのサブウィジェットに分割されるウィジェットがあります。1 つは画像を表示し、もう 1 つは画像を編集するオプションを提供します。画像サブウィジェットは、編集サブウィジェットよりも 5 倍の水平スペースを取る必要があります。この制約をグリッド レイアウトで指定します。ただし、編集サブウィジェットに QGraphicsScene (およびビュー) を追加するとすぐに、制約は無視されます。

いくつかのサイズ ポリシーを試しましたが、どれも希望どおりにはなりませんでしたが、それらの使用経験はあまりありません。

class MapWidget(QWidget):
""" Widget that renders the map and displays properties """
    def __init__(self, main_gui, parent=None):
        super().__init__(parent=parent)
        self.main_gui = main_gui

        # (Re-)Build the ui
        self.layout = QGridLayout()
        self.setLayout(self.layout)

        self.map_scene = QGraphicsScene()
        self.map_scene_view = QGraphicsView()
        self.map_scene_view.setViewport(QGLWidget())
        self.map_scene_view.setScene(self.map_scene)
        self.layout.addWidget(self.map_scene_view, 1, 1, 5, 1)

        blocks_container = QVBoxLayout()
        self.layout.addLayout(blocks_container, 1, 2, 1, 1)

        """
        Here I add other widgets to the blocks_container, 
        however none of those causes problems
        """

        # As soon as I also add this group, both widgets have the same size 
        group_blocks = QGroupBox('Blocks')
        self.blocks_scene = QGraphicsScene()
        self.blocks_scene_view = QGraphicsView()
        self.blocks_scene_view.setViewport(QGLWidget())
        self.blocks_scene_view.setScene(self.blocks_scene)
        group_blocks_layout = QHBoxLayout()
        group_blocks.setLayout(group_blocks_layout)
        group_blocks_layout.addWidget(self.blocks_scene_view)
        blocks_container.addWidget(group_blocks)

比率が 5/6 と 1/6 の 2 つのウィジェットを使用する代わりに、両方のウィジェットが同じサイズを共有するため、画像が小さく見え、編集ウィジェットが大きくなりすぎます。また、「group_blocks」ウィジェットを削除すると、編集サブウィジェットが再び適切なサイズになります。したがって、簡単にするために、含まれている他のすべてのウィジェットを除外しました。

4

1 に答える 1