From 2d26dc27c297d64abee3768d36c57c8917c6b0eb Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 27 Mar 2025 20:34:38 +0100 Subject: [PATCH] qt: add scroll --- gamiki/qt/tiles.py | 49 ++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/gamiki/qt/tiles.py b/gamiki/qt/tiles.py index bcb3ee0..cc32bed 100755 --- a/gamiki/qt/tiles.py +++ b/gamiki/qt/tiles.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# TODO: add QScrollArea +# TODO: disable start() when one is running from sys import argv, exit from enum import IntFlag @@ -32,7 +32,11 @@ class ListItem(QWidget): self.game = game self.coverSize = coverSize if (coverSize > 0) else 48 - self.pixmap=QPixmap(self.game["Icon"] if ("Icon" in self.game) else "") + + if (self.game.icon): + self.pixmap = QPixmap(self.game.get_icon("icon").as_posix()) + else: + self.pixmap = QPixmap("") self.initUI() makeMouseAware(self, [self, self.cover]) @@ -94,7 +98,11 @@ class GridItem(QWidget): self.game = game self.coverSize = coverSize if (coverSize > 0) else 200 self.fixed = fixed - self.pixmap=QPixmap(self.game["Icon"] if ("Icon" in self.game) else "") + + if (self.game.icon): + self.pixmap = QPixmap(self.game.get_icon("square").as_posix()) + else: + self.pixmap = QPixmap("") self.initUI() makeMouseAware(self, [self, self.cover]) @@ -177,38 +185,41 @@ class List(QWidget): self.initUI() def initUI(self): - layout = QVBoxLayout() - #layout.setSpacing(0) + area = QWidget() + layout = QVBoxLayout(area) + layout.setContentsMargins(0, 0, 0, 0) for game in self.games: cover = ListItem(game, self.icon_size) cover.onClick.connect(lambda game: self.onClick.emit(game)) layout.addWidget(cover) - layout.addStretch() - self.setLayout(layout) + self._setScrollLayout(area) -class Grid(QWidget): - onClick = pyqtSignal(Game) + def _setScrollLayout(self, area): + layout = QVBoxLayout() + layout.setContentsMargins(0, 0, 0, 0) - def __init__(self, games: list[Game], icon_size: int = 0): - super().__init__() - - self.games = games - self.icon_size = icon_size - - self.initUI() - + scroll = QScrollArea(self) + scroll.setWidgetResizable(True) + scroll.setWidget(area) + + layout.addWidget(scroll) + + self.setLayout(layout) + +class Grid(List): def initUI(self): - layout = FlowLayout() + area = QWidget() + layout = FlowLayout(area) for game in self.games: cover = GridItem(game, self.icon_size, True) cover.onClick.connect(lambda game: self.onClick.emit(game)) layout.addWidget(cover) - self.setLayout(layout) + self._setScrollLayout(area) if __name__ == '__main__': app = QApplication(argv) -- 2.27.0