Skip to content

Commit

Permalink
Make window scrollable and resizeable
Browse files Browse the repository at this point in the history
Resolves #34
  • Loading branch information
coldfix committed Aug 4, 2024
1 parent 46d445b commit 4aaaa84
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 8 additions & 0 deletions steam_acolyte/window.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ LoginDialog {
);
}

QScrollArea {
background: transparent;
}

UserListWidget {
background: transparent;
}

UserWidget {
background: qlineargradient(
x1: 0, y1: 0,
Expand Down
21 changes: 17 additions & 4 deletions steam_acolyte/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
QDialog, QLabel, QToolButton, QAbstractButton,
QAction, QHBoxLayout, QVBoxLayout, QSizePolicy,
QStyle, QStyleOption, QStylePainter, QWidget,
QSystemTrayIcon, QMenu, QApplication)
QSystemTrayIcon, QMenu, QApplication, QScrollArea)


try: # PyQt >= 5.11
Expand All @@ -32,10 +32,19 @@ def __init__(self, steam, theme):
self._exit = False
self._login = None
self.user_widgets = []
self.userlist = UserListWidget()
self.userlist.setLayout(QVBoxLayout())
scroll = QScrollArea(self)
scroll.setWidgetResizable(True)
scroll.setWidget(self.userlist)
self.setLayout(QVBoxLayout())
self.layout().addWidget(scroll)
self.layout().setContentsMargins(0, 0, 0, 0)

self.setWindowTitle("Steam Acolyte")
self.setWindowIcon(theme.window_icon)
self.setStyleSheet(theme.window_style)

steam.command_received.connect(lambda *_: self.activateWindow())
self.update_userlist()

Expand All @@ -46,19 +55,19 @@ def update_userlist(self):
(u.persona_name.lower(), u.account_name.lower()))
users.append(SteamUser('', '', '', ''))
for user in users:
self.layout().addWidget(UserWidget(self, user))
self.userlist.layout().addWidget(UserWidget(self, user))

def clear_layout(self):
"""Remove all users from the user list widget."""
# The safest way I found to clear a QLayout is to reparent it to a
# temporary widget. This also recursively reparents, hides and later
# destroys any child widgets.
layout = self.layout()
layout = self.userlist.layout()
if layout is not None:
dump = QWidget()
dump.setLayout(layout)
dump.deleteLater()
self.setLayout(QVBoxLayout())
self.userlist.setLayout(QVBoxLayout())

@trace.method
def wait_for_lock(self):
Expand Down Expand Up @@ -271,6 +280,10 @@ def make_user_action(window, user):
return action


class UserListWidget(QWidget):
pass


class UserWidget(ButtonWidget):

"""A button widget for a single user. When clicked, logs in that user.
Expand Down

0 comments on commit 4aaaa84

Please sign in to comment.