How to mapToGlobal a QRect?
-
-
@medyakovvit
No its child's -
Can you show the complete code ?
-
void ChildWidget::mouseMoveEvent(QMouseEvent* event)
{if (event->buttons() & Qt::LeftButton)
{
QRect r=this->geometry();if(r.contains(event->globalPos()))//Also tried event->pos() { qDebug()<<"point inside"; } else { qDebug()<<"point outside"; }
}
QWidget::mouseMoveEvent(event);
}
If the child widget starts at 0,0 works fine...If child widget is not at origin "point outside" will be printed even if the pos is inside.Tried making point global.
-
@Sriu1 said in How to mapToGlobal a QRect?:
If the child widget starts at 0,0 works fine...If child widget is not at origin "point outside" will be printed even if the pos is inside.Tried making point global.
It's been a while since I used this, but mapToGlobal should work just fine!?
> void ChildWidget::mouseMoveEvent(QMouseEvent* event) { if (event->buttons() & Qt::LeftButton) { qDebug() << "Position relative to ChildWidget:" << objectName() << event->pos(); qDebug() << "Position relative to physical screen:" << objectName() << mapToGlobal(event->pos()); } }
-
-
@Sriu1 said in How to mapToGlobal a QRect?:
@J.Hilk Hi,
event()->globalPos() and mapToGlobal(event->pos()) both give same.My problem was with rect.contains().how to map the rect of childWidget to global? So that even if event is occuring anywhere in the screen I should be able to know if its inside the qrect or outsideWell, the same way.
QRect r=this->geometry(); QRect globalRect(mapToGlobal( r.pos() ), r.size() );
-
@J.Hilk Hi,
I tried this
QRect r=this->geometry();
QPoint p(r.x(),r.y());
QRect globalRect(mapToGlobal(p, r.size());getting error
no matching function for call to ‘ChildWidget::mapToGlobal(QPoint&, QSize)’
QRect globalRect(mapToGlobal(p, r.size()); -
@J.Hilk
Still getting....
error: no matching function for call to ‘ChildWidget::mapToGlobal(QPoint&, QSize)’
QRect globalRect(mapToGlobal(p, r.size()));QRect r=this->geometry();
QPoint p(r.x(),r.y());
QRect globalRect(mapToGlobal(p, r.size()));if(!r.contains(event->globalPos()))