c++ - Qt QGraphicsScene does not fitInView() with scrollbars -
qgraphicsview::fitinview() seems ignore presence of scrollbars, apparently overlaid. (it uses hardcoded 2 pixel margin.)
there related bug report (https://bugreports.qt-project.org/browse/qtbug-1047) stating calling fitinview() twice resolve problem.
in case, not. triggering twice manually fits regarding scrollbars. not work:
void mygraphicsview::mousepressevent(qmouseevent *event) { if( event->button() == qt::leftbutton ) { qgraphicsitem* clicked = scene()->itemat( maptoscene( event->pos() ) ); qdebug() << clicked << clicked->boundingrect(); fitinview( clicked, qt::keepaspectratio); fitinview( clicked, qt::keepaspectratio); // doesn't work me qgraphicsview::mousepressevent(event); return; } }
is there workaround?
qt 4.8.1 msvc2010
calling fitinview() twice work, have let qt process events between 2 calls.
this means end redrawing graphicsview twice.
to avoid this, is:
- disable updates
- call fitinview
- call qapplication::processevents()
- call fitinview again
- enable updates
in code this:
bool updatestate = updatesenabled(); setupdatesenabled(false); fitinview(clicked, qt::keepaspectratio); qapplication::processevents(qeventloop::excludeuserinputevents); fitinview(clicked, qt::keepaspectratio); setupdatesenabled(updatestate);
Comments
Post a Comment