Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Set QLineEdit width in 1 symbol

Set QLineEdit width in 1 symbol

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • NorthsoftN Offline
    NorthsoftN Offline
    Northsoft
    wrote on last edited by
    #1

    Hello, how can I set starting width for QLineEdit instance in 1 character? Instance will be placed at QGridLayout. QLineEdit's default width is too big for using table 9x9 QLineEdits. (No way for using models because their usage is a bit complicated for a very simple app).

    JonBJ 1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Did you try setFixedSize(5,5) ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      2
      • NorthsoftN Northsoft

        Hello, how can I set starting width for QLineEdit instance in 1 character? Instance will be placed at QGridLayout. QLineEdit's default width is too big for using table 9x9 QLineEdits. (No way for using models because their usage is a bit complicated for a very simple app).

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @Northsoft
        If you mean get it be exactly 1 character wide, you'd have to call to measure the width of a character in the font (and think about if it's a proportional font) which it is going to use. Is that what you have in mind?

        1 Reply Last reply
        3
        • NorthsoftN Offline
          NorthsoftN Offline
          Northsoft
          wrote on last edited by
          #4

          @dheerendra @JonB I would like to have initial position in one character. I don't want to have fixed size. The initial position is important because initial size of the main window comes from 9 edits in line.

          jsulmJ 1 Reply Last reply
          0
          • NorthsoftN Northsoft

            @dheerendra @JonB I would like to have initial position in one character. I don't want to have fixed size. The initial position is important because initial size of the main window comes from 9 edits in line.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Northsoft As @JonB said the width of you line edit depends on the used font.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            NorthsoftN 1 Reply Last reply
            0
            • jsulmJ jsulm

              @Northsoft As @JonB said the width of you line edit depends on the used font.

              NorthsoftN Offline
              NorthsoftN Offline
              Northsoft
              wrote on last edited by
              #6

              @jsulm I would like to use default font. Is there any way to get a maximum size of a single digit (0-9) without using multiple QPixMap's?

              jsulmJ 1 Reply Last reply
              0
              • NorthsoftN Northsoft

                @jsulm I would like to use default font. Is there any way to get a maximum size of a single digit (0-9) without using multiple QPixMap's?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Northsoft Take a look at https://doc.qt.io/qt-5/qfontmetrics.html

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                NorthsoftN 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @Northsoft Take a look at https://doc.qt.io/qt-5/qfontmetrics.html

                  NorthsoftN Offline
                  NorthsoftN Offline
                  Northsoft
                  wrote on last edited by
                  #8

                  @jsulm thanks a lot, looks like what I need. The last questions are:
                  — how can I convert width of displayed char to width of QLineEdit instance;
                  — and how can I set it as default width? I don't see property for default size.

                  jsulmJ 1 Reply Last reply
                  0
                  • NorthsoftN Northsoft

                    @jsulm thanks a lot, looks like what I need. The last questions are:
                    — how can I convert width of displayed char to width of QLineEdit instance;
                    — and how can I set it as default width? I don't see property for default size.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Northsoft You could use https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qlineedit and https://doc.qt.io/qt-5/stylesheet-customizing.html#the-box-model

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved