GunJack
GunJack

Reputation: 1978

How to obtain the position of Qt widget?

Here is the code.

QPropertyAnimation *animation3 = new QPropertyAnimation (ui->modifyButton, "geometry");
animation3->setDuration(1000);
animation3->setStartValue(QRect(20, 120,  141, 20));
animation3->setStopValue(QRect(20, 70, 141, 20));
animation3->start();

I need the application to automatically determine the "Y" coordinate of modifyButton as it is not fixed and is changing. So how can I do something like this.

int  y = get_y_coordinate_somehow();

animation3->setStartValue(QRect(20, y, 141, 20));start();

Upvotes: 2

Views: 132

Answers (1)

cmannett85
cmannett85

Reputation: 22376

Use the pos() method.

int y = pos().y();

Upvotes: 3

Related Questions