Skip to content

Commit

Permalink
centralize grid layout with row stretches
Browse files Browse the repository at this point in the history
  • Loading branch information
mwinkens committed May 15, 2024
1 parent 2a70324 commit c738441
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/widgets/widget_tile_clicker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class TileClicker(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.gridLayout = QGridLayout()
self.gridLayout.setHorizontalSpacing(0)
self.gridLayout.setVerticalSpacing(0)
self.setLayout(self.gridLayout)
self.tiles = []

Expand All @@ -26,7 +28,7 @@ def setPixmap(self, pixmap: QPixmap):
col = i % TILESET_COL
tile_widget = Tile(i, width=tile_width, height=tile_height)
self.tiles.append(tile_widget)
self.gridLayout.addWidget(tile_widget, row, col)
self.gridLayout.addWidget(tile_widget, row + 1, col + 1)

for i in range(NUM_TILES):
tile = self.tiles[i]
Expand All @@ -35,5 +37,8 @@ def setPixmap(self, pixmap: QPixmap):
x = int((i % TILESET_COL) * tile_width_float)
y = int((i // TILESET_ROW) * tile_height_float)
tile.setPixmap(pixmap.copy(x, y, tile_width, tile_height))
tile.setScaledContents(False)
tile.setMaximumSize(128, 128)

self.gridLayout.setRowStretch(0, 1)
self.gridLayout.setColumnStretch(0, 1)
self.gridLayout.setRowStretch(TILESET_ROW + 1, 1)
self.gridLayout.setColumnStretch(TILESET_COL + 1, 1)

0 comments on commit c738441

Please sign in to comment.