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

Small QLineEdit



  • I am trying to make a Sudoku.I want to take the inputs using QLineEdit but i cant make the size to be small it is always too wide.How can I make the QLineEdits be as small as 1 digit??


  • Moderators

    You can use setFixedWidth(), but be careful about the font.Different systems can have different font styles and sizes, so if you want to go with a fixed size widget make sure the font is fixed too. Otherwise you can use QFontMetrics to get the width of a digit with your current font.


  • Moderators

    You can use setFixedWidth(), but be careful about the font.Different systems can have different font styles and sizes, so if you want to go with a fixed size widget make sure the font is fixed too. Otherwise you can use QFontMetrics to get the width of a digit with your current font.



  • Thanks it worked!.Exactly what i wanted.



  • @DrZod

    I am trying to make a Sudoku.I want to take the inputs using QLineEdit

    That would mean creating 81 QLineEdits for a standard-sized Sudoku board. I'm not sure in Qt, but this may be regarded as bad practice? My thought (in your next iteration, for public release :) ) would be something like a QTableWidget containing at worst a QLabel or better just plain text without a widget most of the time, with a change over to editable (QLineEdit or otherwise) at the instant user clicks into cell, revert back once clicked outside?


Log in to reply