Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reduce the height of QComboBox after applying PyQtDarkTheme #247

Open
ioneater opened this issue Aug 6, 2023 · 3 comments
Open

Comments

@ioneater
Copy link

ioneater commented Aug 6, 2023

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())
@chrizbee
Copy link

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

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

@ioneater
Copy link
Author

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.

@RyanHope
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants