【问题标题】:QLineEdit visible width Setting?QLineEdit 可见宽度设置?
【发布时间】:2012-07-15 23:17:59
【问题描述】:

如何使用 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();

答案更新:或见下文

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

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

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

【问题讨论】:

  • 您是说无论小部件的实际宽度如何,都希望内容区域裁剪到特定大小?您仍然希望允许任何数据大小和小部件宽度,但不允许内容区域宽度?

标签: c++ qt user-interface


【解决方案1】:
firstNameText->setMaximumWidth(100);
firstNameText->setFixedWidth(120);

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

【讨论】:

    猜你喜欢
    • 2015-07-30
    • 1970-01-01
    • 2020-08-12
    • 1970-01-01
    • 2014-10-17
    • 2017-01-27
    • 1970-01-01
    • 2014-09-24
    • 1970-01-01
    相关资源
    最近更新 更多