简体   繁体   English

更改QLineEdit的x和y位置

[英]Change x and y position of a QLineEdit

I would like to change the position of the lineEdit (or even a PushButton if it's not possible with the lineEdit) from my Qt application, according to the input given. 根据给定的输入,我想从我的Qt应用程序中更改lineEdit的位置(如果lineEdit无法使用,甚至更改一个PushButton)。 So let's say that I want the x position to be 150 pixels, then I would insert 150 into the lineEdit. 因此,假设我希望x位置为150像素,然后将150插入lineEdit中。 Is there any way to do this? 有什么办法吗?

I've already tried this: 我已经尝试过了:

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);
}

It depends on how the QLineEdit is initially positioned. 这取决于QLineEdit最初的放置方式。 Is it placed within a layout? 是否放置在布局中? If so, you won't be able to place it at an absolute position. 如果是这样,您将无法将其放置在绝对位置。

But if it does not belong to any layout, you can just use the move method: 但是,如果它不属于任何布局,则可以使用move方法:

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

Here's the docs . 这是docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM