Skip to content

Commit

Permalink
Fix Color properties widgets setting (#3021)
Browse files Browse the repository at this point in the history
Add stylesheet to link and jump properties to make scroll area backgrounds transparent

Re #3012
  • Loading branch information
ptsavol authored Dec 3, 2024
1 parent e318e36 commit ca3e446
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 21 deletions.
14 changes: 9 additions & 5 deletions spinetoolbox/ui/jump_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QAbstractItemView, QApplication, QComboBox, QGridLayout,
QGroupBox, QHBoxLayout, QHeaderView, QPushButton,
QRadioButton, QScrollArea, QSizePolicy, QSpacerItem,
QToolButton, QTreeView, QVBoxLayout, QWidget)
from PySide6.QtWidgets import (QAbstractItemView, QApplication, QComboBox, QFrame,
QGridLayout, QGroupBox, QHBoxLayout, QHeaderView,
QPushButton, QRadioButton, QScrollArea, QSizePolicy,
QSpacerItem, QToolButton, QTreeView, QVBoxLayout,
QWidget)

from spinetoolbox.widgets.code_text_edit import CodeTextEdit
from spinetoolbox import resources_icons_rc
Expand All @@ -39,16 +40,19 @@ def setupUi(self, Form):
if not Form.objectName():
Form.setObjectName(u"Form")
Form.resize(307, 400)
Form.setStyleSheet(u"QScrollArea { background: transparent; }\n"
"QScrollArea > QWidget > QWidget { background: transparent; }")
self.verticalLayout_3 = QVBoxLayout(Form)
self.verticalLayout_3.setSpacing(0)
self.verticalLayout_3.setObjectName(u"verticalLayout_3")
self.verticalLayout_3.setContentsMargins(0, 0, 0, 0)
self.scrollArea = QScrollArea(Form)
self.scrollArea.setObjectName(u"scrollArea")
self.scrollArea.setFrameShape(QFrame.Shape.NoFrame)
self.scrollArea.setWidgetResizable(True)
self.scrollAreaWidgetContents = QWidget()
self.scrollAreaWidgetContents.setObjectName(u"scrollAreaWidgetContents")
self.scrollAreaWidgetContents.setGeometry(QRect(0, 0, 305, 398))
self.scrollAreaWidgetContents.setGeometry(QRect(0, 0, 307, 400))
self.verticalLayout = QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout.setSpacing(0)
self.verticalLayout.setObjectName(u"verticalLayout")
Expand Down
13 changes: 10 additions & 3 deletions spinetoolbox/ui/jump_properties.ui
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<property name="windowTitle">
<string>Form</string>
</property>
<property name="styleSheet">
<string notr="true">QScrollArea { background: transparent; }
QScrollArea &gt; QWidget &gt; QWidget { background: transparent; }</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
Expand All @@ -44,6 +48,9 @@
</property>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="frameShape">
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
Expand All @@ -52,8 +59,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>305</width>
<height>398</height>
<width>307</width>
<height>400</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down Expand Up @@ -157,7 +164,7 @@
<string>...</string>
</property>
<property name="icon">
<iconset resource="resources/resources_icons.qrc">
<iconset>
<normaloff>:/icons/file-upload.svg</normaloff>:/icons/file-upload.svg</iconset>
</property>
</widget>
Expand Down
6 changes: 5 additions & 1 deletion spinetoolbox/ui/link_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,20 @@ def setupUi(self, Form):
if not Form.objectName():
Form.setObjectName(u"Form")
Form.resize(362, 404)
Form.setStyleSheet(u"QScrollArea { background: transparent; }\n"
"QScrollArea > QWidget > QWidget { background: transparent; }")
self.verticalLayout_3 = QVBoxLayout(Form)
self.verticalLayout_3.setSpacing(0)
self.verticalLayout_3.setObjectName(u"verticalLayout_3")
self.verticalLayout_3.setContentsMargins(0, 0, 0, 0)
self.scrollArea = QScrollArea(Form)
self.scrollArea.setObjectName(u"scrollArea")
self.scrollArea.setFrameShape(QFrame.Shape.NoFrame)
self.scrollArea.setWidgetResizable(True)
self.scrollAreaWidgetContents = QWidget()
self.scrollAreaWidgetContents.setObjectName(u"scrollAreaWidgetContents")
self.scrollAreaWidgetContents.setGeometry(QRect(0, 0, 360, 402))
self.scrollAreaWidgetContents.setGeometry(QRect(0, 0, 362, 404))
self.scrollAreaWidgetContents.setAutoFillBackground(False)
self.verticalLayout = QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout.setSpacing(0)
self.verticalLayout.setObjectName(u"verticalLayout")
Expand Down
14 changes: 12 additions & 2 deletions spinetoolbox/ui/link_properties.ui
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<property name="windowTitle">
<string>Form</string>
</property>
<property name="styleSheet">
<string notr="true">QScrollArea { background: transparent; }
QScrollArea &gt; QWidget &gt; QWidget { background: transparent; }</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
Expand All @@ -44,6 +48,9 @@
</property>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="frameShape">
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
Expand All @@ -52,10 +59,13 @@
<rect>
<x>0</x>
<y>0</y>
<width>360</width>
<height>402</height>
<width>362</width>
<height>404</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
Expand Down
2 changes: 1 addition & 1 deletion spinetoolbox/ui/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def setupUi(self, MainWindow):
self.tab_no_selection.setObjectName(u"tab_no_selection")
self.verticalLayout_14 = QVBoxLayout(self.tab_no_selection)
self.verticalLayout_14.setObjectName(u"verticalLayout_14")
self.verticalLayout_14.setContentsMargins(6, 6, 6, 6)
self.verticalLayout_14.setContentsMargins(0, 0, 0, 0)
self.label_no_selection = QLabel(self.tab_no_selection)
self.label_no_selection.setObjectName(u"label_no_selection")
self.label_no_selection.setAlignment(Qt.AlignmentFlag.AlignCenter)
Expand Down
8 changes: 4 additions & 4 deletions spinetoolbox/ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,16 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_14">
<property name="leftMargin">
<number>6</number>
<number>0</number>
</property>
<property name="topMargin">
<number>6</number>
<number>0</number>
</property>
<property name="rightMargin">
<number>6</number>
<number>0</number>
</property>
<property name="bottomMargin">
<number>6</number>
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_no_selection">
Expand Down
14 changes: 9 additions & 5 deletions spinetoolbox/widgets/properties_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,20 @@ def set_color_and_icon(self, base_color, icon=None):
bnw_pixmap = QPixmap(icon)
self._pixmap = QPixmap(bnw_pixmap.size())
self._pixmap.fill(self._fg_color)
self._pixmap.setMask(bnw_pixmap.createMaskFromColor(Qt.transparent))
self._pixmap.setMask(bnw_pixmap.createMaskFromColor(Qt.GlobalColor.transparent))

def eventFilter(self, obj, ev):
if ev.type() == QEvent.Paint:
if ev.type() == QEvent.Type.Paint:
painter = QPainter(obj)
painter.fillRect(obj.rect(), QColor(255, 255, 255, 180))
return super().eventFilter(obj, ev)

def paintEvent(self, ev):
"""Paints background"""
"""Paints background.
Note: The backgrounds of the properties widget's QScrollArea
and the scrollAreaWidgetContents QWidget are set to transparent in stylesheets.
"""
settings = self._toolbox.qsettings()
if settings.value("appSettings/colorPropertiesWidgets", defaultValue="false") == "false":
super().paintEvent(ev)
Expand All @@ -80,10 +84,10 @@ def paintEvent(self, ev):
new_transparent_widgets -= self._transparent_widgets
self._transparent_widgets |= new_transparent_widgets
for widget in new_transparent_widgets:
widget.setAttribute(Qt.WA_NoSystemBackground)
widget.setAttribute(Qt.WidgetAttribute.WA_NoSystemBackground)
widget.installEventFilter(self)
try:
widget.viewport().setAttribute(Qt.WA_TranslucentBackground)
widget.viewport().setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
except AttributeError:
pass
rect = self.rect()
Expand Down

0 comments on commit ca3e446

Please sign in to comment.