UN-GCPDS / qt-material

Material inspired stylesheet for PySide2, PySide6, PyQt5 and PyQt6
https://qt-material.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
2.27k stars 241 forks source link

Remove .QSlider #19

Closed leon-thomm closed 3 years ago

leon-thomm commented 3 years ago

Hey! I'm not entirely sure what writing .QSlider in the qss would mean, but it produces a bug, so I suggest changing it.

If you specify the style sheet properties for a slider using .QSlider, to at runtime added sliders it only applies if they are part of a widget that gets added (even though the QSlider is a QWidget, the style isn't applied at all when added at runtime to an existing layout). This only applies on custom implementations of QSlider, inserting plain QSliders seems to work. This code reproduces that:

from PySide2.QtCore import Qt
from PySide2.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QSlider
import sys, qt_material

class WidgetWithSlider(QWidget):
    def __init__(self):
        QWidget.__init__(self)

        self.setLayout(QVBoxLayout())
        self.layout().addWidget(QSlider(Qt.Horizontal))

class SliderWidget(QSlider):
    def __init__(self):
        QSlider.__init__(self, Qt.Horizontal)

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        w = QWidget()
        w.setLayout(QVBoxLayout())
        self.setCentralWidget(w)

    def mousePressEvent(self, event) -> None:
        self.centralWidget().layout().addWidget(SliderWidget())
        self.centralWidget().layout().addWidget(WidgetWithSlider())

if __name__ == '__main__':
    app = QApplication()
    qt_material.apply_stylesheet(app, theme='dark_blue.xml')
    mw = MainWindow()
    mw.show()

    sys.exit(app.exec_())

Just click somewhere into the window. I figured it works when manually applying the template stylesheet and literally just removing the dots of .QSlider. I noticed there are many of these .somwidget specifications in the template stylesheet, so this might apply on other widgets as well, so it'd be nice if you could take a closer look at that. I'm on Windows 10 with Python 3.8 in case that matters.

YeisonCardona commented 3 years ago

Hi @leon-thomm

I don't remember what was the real reason to work with classes instead of elements, but looking at your example I think that must be an error on my first test windows. I just removed all class selectors and replaced them with elements selectors, the .QWidget were replaced with explicit selectors like: QToolBox > QWidget and QTabWidget > QWidget.

Thanks a lot.

leon-thomm commented 3 years ago

Yep, I think that works now, thanks for the quick fix!

leon-thomm commented 3 years ago

Possible that you forgot QLineEdit? still the same there

YeisonCardona commented 3 years ago

Hi @leon-thomm With .QLineEdit the style is applied to only explicit QLineEdit widgets and not to editable items like in QListView. I will remove .QLineEdit and configure as unset all subwidgets.

Thanks.

leon-thomm commented 3 years ago

Ah, I understand the initial issues now. But this also means that no custom subclasses of QLineEdit will be styled, right? Which I guess isn't what one wants usually, no? Wouldn't it be more sustainable to add specific styling rules for things like QListView items?

YeisonCardona commented 3 years ago

The default style for editable widgets looks pretty good, is simple and functional.