如何设置QLineEdit的可见宽度为Qt 4.8.1或更高版本。例如,将可见宽度设置为某个像素大小或字符宽度。我希望只使用C++而不是QML。QLineEdit可见宽度设置?
我的想法是在这个块的方向:
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();
答案更新:(或见下文)
firstNameText->setMaximumWidth(100);
firstNameText->setFixedWidth(120);
middleIntText->setMaximumWidth(50);
middleIntText->setFixedWidth(60);
lastNameText->setMaximumWidth(100);
lastNameText->setFixedWidth(120);
你是说你想让内容区域裁剪到一定的大小,而不管widget的实际宽度是多少?您仍然希望允许任何数据大小和小部件宽度,但不允许内容区域宽度? – jdi 2012-07-17 03:53:49