c++ - 更改 QLineEdit 的 x 和 y 位置

标签 c++ qt qlineedit

我想根据给定的输入从我的 Qt 应用程序中更改 lineEdit 的位置(或者甚至是 PushButton,如果 lineEdit 不可能的话)。 假设我希望 x 位置为 150 像素,那么我会将 150 插入到 lineEdit 中。 有什么办法吗?

我已经试过了:

void DrawTest::on_lineEdit_returnPressed()
{
    QString x = ui->lineEdit->text();
    qDebug() << "x: " << x;
    QString style = "QLineEdit {"
                    ":" +ui->lineEdit->text()+ "px;"
                    "background-color: #FF00FF;"
                    "};";
    qDebug() << "Style: " << style;
    ui->lineEdit->setStyleSheet(style);
}

最佳答案

这取决于 QLineEdit 最初的定位方式。它是否放置在布局中?如果是这样,您将无法将其放置在绝对位置。

但是如果它不属于任何布局,你可以直接使用move方法:

ui->lineEdit->move(x, y);

Here's the docs .

关于c++ - 更改 QLineEdit 的 x 和 y 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57992228/

相关文章:

qt - Qt 可以用于为 windows IoT 核心开发应用程序吗?

python - PyQt,设置特定数量的行编辑输入

c++ - 通过 C++ 和 Qt 访问 Googles Book API

c++ - 获取 "error LNK2019: unresolved external symbol"

c++ - 如何在 Qt GUI 应用程序中嵌入输出控制台窗口?

c++ - 保留 QTextEdit 中的光标位置

regex - 如何限制 QLineEdit 中的表达式

c++ - 如何使用 x264 与 ffmpeg 进行编码?

c++ - 如何仅针对一个开关盒 block 禁用 "enumeration value not explicitly handled in switch"?

c++ - 二维插值