5yutan5 / PyQtDarkTheme

A flat dark theme for PySide and PyQt.

Home Page:https://pyqtdarktheme.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to reduce the height of QComboBox after applying PyQtDarkTheme

ioneater opened this issue · comments

I really like this theme. To make my layout consistent I need to reduce the height of all QComboBoxes.
Before qdarktheme.setup_theme this can be done by setting maximumHeight or stylesheets, but after qdarktheme.setup_theme these no longer work.
Is there a way to change the height or to not apply the style to QComboBoxes so they can be styled individually?

Below is a simple example. After you click on qdarktheme, reduceHeight is ineffective.

import sys
import qdarktheme
from PyQt6.QtWidgets import QApplication,QWidget,QPushButton,QVBoxLayout,QLabel,QComboBox

class Foo(QWidget):

    def __init__(self):
        super().__init__()        
        lay = QVBoxLayout(self)  
        b = QPushButton('qdarktheme')
        b.clicked.connect(self.setupTheme)
        lay.addWidget(b)        
        b = QPushButton('reduceHeight')
        b.clicked.connect(self.reduceHeight)
        lay.addWidget(b)        
        qcb = QComboBox()
        lay.addWidget(QLabel('Test'))
        lay.addWidget(qcb)
        self.qcb = QComboBox()
        lay.addWidget(QLabel('Test'))
        lay.addWidget(self.qcb)
        
    def reduceHeight(self):
        self.qcb.setMaximumHeight(10) # only moves combobox when qdarktheme applied
        # self.qcb.setStyleSheet('QComboBox {padding: 0px;margin: 0px;}') # no effect when qdarktheme applied
    
    def setupTheme(self):
        qdarktheme.setup_theme(theme='light', corner_shape="sharp")

if __name__ == '__main__':
    app = QApplication(sys.argv)    
    app.setStyle('Fusion')       
    
    mainWindow = Foo()
    mainWindow.show()
    sys.exit(app.exec())

Same issue here. Workaround to adapt QComboBox to QLineEdit, QSpinBox, etc.:

qdarktheme.setup_theme(additional_qss="QComboBox { min-height: 1em; padding: 3px 4px; }")

Thank you!
I ended up custimizing the standardPallete and styleSheet instead of using this theme, which gave similar results and did not require any workarounds.

I have the same issue with QTableView, there is so much extra space in the cells when qdarktheme is applied than standard