QGraphicsView fitInView margins

别说谁变了你拦得住时间么 提交于 2020-01-03 15:13:12

问题


Why this:

graphics_view->fitInView(scene->sceneRect(), Qt::KeepAspectRatio);

doesn’t work as expected ? It isn't fitting the scene rect correctly, showing margins around it.


回答1:


The cause is this: https://bugreports.qt.io/browse/QTBUG-42331 - please vote on it on the qt bug tracker to up its priority.

In short, fitInView has hardcoded margins and this can cause all kinds of havoc - the least of which is that now you lose a few pixels of display area and might also force unnecessary rescaling.

You can fix the problem by reimplementing fitInView, based on the existing implementation but removing it's ridiculous margins. An example of that is available here in python, based on the original C++ version:

https://github.com/nevion/pyqimageview/blob/master/qimageview/widget.py#L276




回答2:


I figured out what the problem was, it is described in this question. The main cause of the problem is that you shouldn't call fitInView before the form is shown.




回答3:


You can fix it reimplementing the original fitInView method, but without including the margins. Check my C++ solution at: https://stackoverflow.com/a/42474510/6050364



来源:https://stackoverflow.com/questions/19640642/qgraphicsview-fitinview-margins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!