Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QLineEdit visible width Setting?

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);
like image 483
Brandon Clark Avatar asked Jul 17 '12 03:07

Brandon Clark


1 Answers

firstNameText->setMaximumWidth(100);
firstNameText->setFixedWidth(120);

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

like image 185
user1529294 Avatar answered Oct 03 '22 21:10

user1529294