pythonqtpysideqlineedit

How can I limit text box width of QLineEdit to display at most four characters?


I am working with a GUI based on PySide. I made a (one line) text box with QLineEdit and the input is just four characters long, a restriction I already successfully applied.

The problem is I have a wider than needed text box (i.e. there is a lot of unused space after the text). How can I shorten the length of the text box?

I know this is something that is easily fixed by designing the text box with Designer; however, this particular text box is not created in Designer.


Solution

  • If what you want is modify your QLineEdit width and fix it, use:

    #setFixedWidth(int w)
    MyLineEdit.setFixedWidth(120)