Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

MacOS: QLineEdit height when changing font-size in stylesheet



  • Hi,

    My Problem is that under MacOS/OSX with the default "macintosh" theme QLineEdits don't change their height when I set a larger font with "setStyleSheet".

    It works correctly when setting the fontsize with "setPointSize" or when I'm using another style like "fusion".

    Here's a sample script:

    import sys
    from PySide2.QtWidgets import *
    import PySide2
    
    class Form(QDialog):
        def __init__(self, parent=None):
            super(Form, self).__init__(parent)
    
            self.edit1 = QLineEdit(PySide2.__version__)
            self.edit2 = QLineEdit(PySide2.__version__)
            self.edit3 = QLineEdit(PySide2.__version__)
    
            layout = QVBoxLayout()
            layout.addWidget(self.edit1)
            layout.addWidget(self.edit2)
            layout.addWidget(self.edit3)
            self.setLayout(layout)
    
            f = self.edit1.font()
            f.setPointSize(27)
            self.edit1.setFont(f)
    
            self.edit2.setObjectName("edit2")
            self.setStyleSheet("QLineEdit#edit2 {font-size: 27pt}")
            self.edit3.setStyleSheet("font-size: 27pt")
    
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        form = Form()
        form.show()
        sys.exit(app.exec_())
    

    Result without "-style" or with "-style macintosh":

    0_1568966254196_Bildschirmfoto 2019-09-20 um 09.49.07.png

    Result with "-style fusion":
    0_1568966299385_Bildschirmfoto 2019-09-20 um 09.50.08.png

    Is there anything missing/wrong in my script or is this a bug in QT?

    Thanks.


  • Banned

    Okay cannot answer if its a bug or just an undocumented feature ;) but I was experiencing presentation issues on Win10 so its not just related to the Mac OS still I fixed it using too different commands

    if __name__ == "__main__":
            GuiThred = QApplication([])
            GuiThred.setStyle('fusion')
    
    class MainWIndow(QMainWindow):
    ...
        self.setStyle(QStyleFactory.create('Cleanlooks'))
    

    Of course there are other styles other than Fusion but I also read that some folks feel you ought not to change the style but personally if its not displaying correctly and that fixes the issue frankly I am not so concerned unless the program specs call for the program to allow for various presentation styles because unless it does I am not going to go down that overly extensive path due to the amount of testing that would be required to support that implementation. My motto make it work and once you have a working version then decide if it is worth the effort to implement something more expansive the answer most of the time is no it is not.


Log in to reply