gpt4 book ai didi

c++ - QLineEdit 可见宽度设置?

转载 作者:IT老高 更新时间:2023-10-28 23:17:31 28 4
gpt4 key购买 nike

如何使用 Qt 4.8.1 及更高版本设置 QLineEdit 的可见宽度。示例是将可见宽度设置为某个像素大小或字符宽度。我希望只使用 C++ 而不是 QML。

我的想法是这个 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();

答案更新:(或见下文)

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

middleIntText->setMaximumWidth(50);
middleIntText->setFixedWidth(60);

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

最佳答案

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

您可以使用这两个功能,它们会相应地调整宽度。

关于c++ - QLineEdit 可见宽度设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11515661/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com