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. [Solved] QLineEdit visible width setting?
QtWS25 Last Chance

[Solved] QLineEdit visible width setting?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 11.2k 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.
  • W Offline
    W Offline
    weblife
    wrote on last edited by
    #1

    How may I set the visible width of QLineEdit with Qt 4.8.1 and up. Example would be to set the visible width to some pixel size or character width. I wish to only use C++ not QML.

    My thought is in the direction of this block:
    @ QHBoxLayout *nameRow = new QHBoxLayout;

        QLineEdit   *firstNameText = new QLineEdit,
                    *middleIntText = new QLineEdit,
                    *lastNameText  = new QLineEdit;
    
        //Whatever method is needed here to edit visible width
        //firstNameText->???
        //middleIntText->???
        //lastNameText->???
    
        nameRow->addWidget(firstNameText);
        nameRow->addWidget(middleIntText);
        nameRow->addWidget(lastNameText);
    
        layout->addLayout(nameRow);
    
        QWidget window;
        window.setLayout(layout);
        window.show();@
    

    Answer Update:
    @ firstNameText->setMaximumWidth(100);
    firstNameText->setFixedWidth(120);
    middleIntText->setMaximumWidth(50);
    middleIntText->setFixedWidth(60);
    lastNameText->setMaximumWidth(100);
    lastNameText->setFixedWidth(120);@
    Thanks to a user at "StackOverflow":http://stackoverflow.com/questions/11515661/qlineedit-visible-width-setting/11515830#11515830

    Brandon Clark

    Brandon Clark
    www.themindspot.com

    1 Reply Last reply
    0
    • A Offline
      A Offline
      absfrm
      wrote on last edited by
      #2

      do you want to resize your widget?
      use this :
      @
      //for width
      ui->lineEdit->setFixedWidth(300);

      //for height
      ui->lineEdit->setFixedHeight(100);

      //for both
      ui->lineEdit->setFixedSize(300,100);
      @

      If You Want You Can!

      1 Reply Last reply
      0
      • W Offline
        W Offline
        weblife
        wrote on last edited by
        #3

        @ firstNameText->setMaximumWidth(100);
        firstNameText->setFixedWidth(120);
        middleIntText->setMaximumWidth(50);
        middleIntText->setFixedWidth(60);
        lastNameText->setMaximumWidth(100);
        lastNameText->setFixedWidth(120);@

        Thanks to a user at "StackOverflow":http://stackoverflow.com/questions/11515661/qlineedit-visible-width-setting/11515830#11515830

        Brandon Clark
        www.themindspot.com

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #4

          setFixedWidth will set both min and maximum width, so doing setMaximumWidth before is redundant.

          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