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:

  1. disable updates
  2. call fitinview
  3. call qapplication::processevents()
  4. call fitinview again
  5. 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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -