i have qgraphicsview
widget lots of items on scene. panning view on ctr+left mouse click , zooming rectangle of rubber band created left mouse button drag. not able see rubber band selection rectangle (dotted lines) whereas rubberband selection functionality works fine. can me understand this?.
i use these flags in view:
settransformationanchor(qgraphicsview::anchorundermouse); setviewportupdatemode(qgraphicsview::smartviewportupdate); setrenderhints(qpainter::highqualityantialiasing | qpainter::smoothpixmaptransform); setoptimizationflag(qgraphicsview::dontsavepainterstate,true); setcachemode(qgraphicsview::cachebackground); setoptimizationflag(qgraphicsview::dontadjustforantialiasing); setviewport(new qglwidget);
below event handlers.
mouse press event handler:
void myview::mousepressevent(qmouseevent* event) { if(event->button()==qt::leftbutton) { if(event->modifiers()==qt::controlmodifier) { setdragmode(qgraphicsview::nodrag); m_rubberbandactive = false; mousepressed=true; m_lastdragpos = event->pos(); return; } else { setdragmode(qgraphicsview::rubberbanddrag); m_rubberbandorigin = event->pos(); m_rubberbandactive = true; } } event->accept(); } else { qwidget::mousepressevent(event); } }
mouse move event:
void myview::mousemoveevent(qmouseevent* event) { if(mousepressed) { qpointf delta = maptoscene(event->pos()) - maptoscene(m_lastdragpos); this->panview(delta); m_lastdragpos = event->pos(); return; } event->accept(); }
mouse release event handler:
void myview::mousereleaseevent(qmouseevent *event) { if (m_rubberbandactive) { qpoint rubberbandend = event->pos(); qrectf zoomrectinscene = qrectf(maptoscene(m_rubberbandorigin),maptoscene(rubberbandend)); fitinview(zoomrectinscene, qt::keepaspectratio); m_rubberbandactive = false; } mousepressed=false; event->accept(); }
pan view:
void myview::panview(qpointf delta) { qpoint viewcenter(viewport()->width() / 2 + delta.x(), viewport()->height() / 2 + delta.y()); qpointf newcenter = maptoscene(viewcenter); centeron(newcenter); }
Comments
Post a Comment