void ShapedClock::mousePressEvent(QMouseEvent *event){ if (event->button() == Qt::LeftButton) { dragPosition = event->globalPos() - frameGeometry().topLeft(); qDebug() << "klik" << dragPosition; event->accept(); }}void ShapedClock::mouseMoveEvent(QMouseEvent *event){ if (event->buttons() & Qt::LeftButton) { qDebug() << "move" << pos() << event->globalPos() << dragPosition << (event->globalPos() - dragPosition); move(event->globalPos() - dragPosition); event->accept(); }}
klik QPoint(639,525)move QPoint(0,0) QPoint(640,525) QPoint(639,525) QPoint(1,0)
click QPoint(54,22)move QPoint(320,308) QPoint(375,330) QPoint(54,22) QPoint(321,308)move QPoint(321,308) QPoint(376,331) QPoint(54,22) QPoint(322,309)move QPoint(322,309) QPoint(378,333) QPoint(54,22) QPoint(324,311)move QPoint(324,311) QPoint(379,333) QPoint(54,22) QPoint(325,311)move QPoint(325,311) QPoint(380,334) QPoint(54,22) QPoint(326,312)move QPoint(326,312) QPoint(381,334) QPoint(54,22) QPoint(327,312)move QPoint(327,312) QPoint(381,335) QPoint(54,22) QPoint(327,313)move QPoint(327,313) QPoint(382,336) QPoint(54,22) QPoint(328,314)
static bool fix(QWidget *w){ XWindowAttributes attrs; XGetWindowAttributes(QX11Info::display(), w->effectiveWinId(), &attrs); qDebug() << attrs.x << attrs.y; return true;}void ShapedClock::mousePressEvent(QMouseEvent *event){ if (event->button() == Qt::LeftButton) { static bool b = fix(this); dragPosition = event->globalPos() - frameGeometry().topLeft(); event->accept(); }}