Bra*_*ark 12 c++ user-interface qt
如何使用Qt 4.8.1及更高版本设置QLineEdit的可见宽度.示例是将可见宽度设置为某个像素大小或字符宽度.我希望只使用C++而不是QML.
我的想法是在这个块的方向:
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();
Run Code Online (Sandbox Code Playgroud)
答案更新:(或见下文)
firstNameText->setMaximumWidth(100);
firstNameText->setFixedWidth(120);
middleIntText->setMaximumWidth(50);
middleIntText->setFixedWidth(60);
lastNameText->setMaximumWidth(100);
lastNameText->setFixedWidth(120);
Run Code Online (Sandbox Code Playgroud)
小智 13
firstNameText->setMaximumWidth(100);
firstNameText->setFixedWidth(120);
Run Code Online (Sandbox Code Playgroud)
您可以使用这两个功能,他们将相应地调整宽度.