Important: Please read the 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()
            f = self.edit1.font()
            self.setStyleSheet("QLineEdit#edit2 {font-size: 27pt}")
            self.edit3.setStyleSheet("font-size: 27pt")
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        form = Form()

    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?


  • 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([])
    class MainWIndow(QMainWindow):

    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