QLineEdit visible width Setting?

15,448
firstNameText->setMaximumWidth(100);
firstNameText->setFixedWidth(120);

You can use thse two functions and they will adjust the width accordingly.

Share:
15,448

Related videos on Youtube

Brandon Clark
Author by

Brandon Clark

My education is backed up with a Master in Software Engineering and Bachelor in Business Information and Decision Systems. Engineering scalable software services and architecture systems are the backbone of my experience. My education means a lot but my experience is everything. I have been fortunate enough to work in areas of 3D image processing, CI/CD design and application, micro services, container orchastration, product and release management. l am a lucky man and love my career. Specialties: Software Architecture • Application Design • User Interface Design • Data Modeling

Updated on September 16, 2022

Comments

  • Brandon Clark
    Brandon Clark over 1 year

    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: (or see below)

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