Skip to content

Commit

Permalink
Improve docstring and add example file
Browse files Browse the repository at this point in the history
  • Loading branch information
DanicaSTFC committed Aug 7, 2024
1 parent 210c665 commit 2186ddc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion eqt/ui/NoBorderScrollArea.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
class NoBorderScrollArea(QScrollArea):
def __init__(self, widget, parent=None):
"""Creates an instance of a QScrollArea and sets its border to none.
Sets its widget to resizable."""
Sets its widget to resizable. Due to a bug in `qdarkstyle`, the PushButtons in the
widget do not inherit the right style. The init applies `qdarkstyle` to all the buttons
present in the widget when the object is created. Any button added to the widget after the
init is invoked will not be styled as expected. The method `apply_qdarkstyle_to_buttons`
needs to be invoked after the object is instanced."""
super().__init__(parent)
self.setStyleSheet("QScrollArea { border: none; }")
self.setWidgetResizable(True)
Expand Down
39 changes: 39 additions & 0 deletions examples/NoBorderScrollArea_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys

from PySide2 import QtWidgets
from PySide2.QtWidgets import QPushButton

from eqt.ui.NoBorderScrollArea import NoBorderScrollArea


class MainUI(QtWidgets.QMainWindow):
def __init__(self, parent=None):
"""Any button added after the `NoBorderScrollArea` is instanced will not be styled as
expected, due to the bug in `qdarkstyle`. The method `apply_qdarkstyle_to_buttons` needs
to be invoked."""
QtWidgets.QMainWindow.__init__(self, parent)

layout = QtWidgets.QVBoxLayout()
widg = QtWidgets.QWidget()
widg.setLayout(layout)

layout.addWidget(QPushButton("Test"))
layout.addWidget(QPushButton("Test2"))

self.scroll_area_widget = NoBorderScrollArea(widg)

layout.addWidget(QPushButton("Test3"))
self.scroll_area_widget.apply_qdarkstyle_to_buttons(widg)
layout.addWidget(QPushButton("Test4"))

self.setCentralWidget(self.scroll_area_widget)

self.show()


if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)

window = MainUI()

sys.exit(app.exec_())

0 comments on commit 2186ddc

Please sign in to comment.