给按钮创建点击事件槽函数,在函数里面获取按钮坐标
ui->pushButton0->x();
ui->pushButton0->y();
QString X_Y
X_Y=QString("X=%1 Y=%2!").arg(QString::number(ui->pushButton0->x())).arg(QString::number(ui->pushButton0->y())) );
获取x,y坐标
ui->label->setText(X_Y);
用QT事件:
void mouseMoveEvent ( QMouseEvent * e )
{
int xPos, yPos;
xPos = e->globalPos().x() ;
yPos = e->globalPos().y() ;
然后将xPos,yPos转为QString ;
label->setText(QString);
}