qt - QRubberBand on a definite label -


strange things happening: need use rubberband on label. here's code:

    qrubberband *rubberband;     qpoint mypoint;  void mainwindow::mousepressevent(qmouseevent *event){      mypoint = event->pos();     rubberband = new qrubberband(qrubberband::rectangle, ui->label_2);//new rectangle band     rubberband->setgeometry(qrect(mypoint, ui->label_2->size()));     rubberband->show(); }  void mainwindow::mousemoveevent(qmouseevent *event){     rubberband->setgeometry(qrect(mypoint, event->pos()).normalized());//area bounding }  void mainwindow::mousereleaseevent(qmouseevent *event){     rubberband->hide();// hide on mouse release     rubberband->clearmask(); } 

everything works there's 1 trouble - rubberbound starts paint little bit lower coursor set around 100-150px.

what doing wrong ?

the event->pos() in different coordinate system of label, , rubberband.

http://qt-project.org/doc/qt-4.8/qwidget.html#mapfrom

http://qt-project.org/doc/qt-4.8/qwidget.html#mapfromglobal

http://qt-project.org/doc/qt-4.8/qwidget.html#mapfromglobal

http://qt-project.org/doc/qt-4.8/application-windows.html

http://qt-project.org/doc/qt-4.8/qwidget.html#geometry-prop

http://qt-project.org/doc/qt-4.8/qwidget.html#rect-prop

you need map event->pos() different coordinate system compensate offset.

edit: here example.

// in constructor set rubberband zero. rubberband = 0;  void mainwindow::mousepressevent(qmouseevent *event){      mypoint = ui->label->mapfromglobal(this->maptoglobal(event->pos()));     // mypoint = ui->label->mapfrom(this, event->pos());     // mypoint = this->mapto(ui->label, event->pos());     if(rubberband == 0) // should add not have memory leak         rubberband = new qrubberband(qrubberband::rectangle, ui->label_2);//new rectangle band     rubberband->setgeometry(qrect(mypoint, ui->label_2->size()));     rubberband->show(); } 

in qrubberband description shows how implemented if being used on widget mouseevents triggered with. since using on different widget widgets mouse events, have map coordinates.

hope helps.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -