0

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. So let's say that I want the x position to be 150 pixels, then I would insert 150 into the 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);
}

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Possible duplicate of [QPushButton alignment on top another widget](https://stackoverflow.com/questions/47908521/qpushbutton-alignment-on-top-another-widget) – Maxim Paperno Sep 19 '19 at 04:24

1 Answers1

4

It depends on how the QLineEdit is initially positioned. 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:

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

Here's the docs.

José Tomás Tocino
  • 9,873
  • 5
  • 44
  • 78