Zooming a view in PyQt?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 09:06:27

问题


I have a simple to do tree application that displays a QTreeView inside of a QMainWindow. I want to give the user the ability to change the magnification level of the content (using a spinbox most likely), but without actually changing the underlying font size of the text.

Is there a way to do this without changing my whole app to a QGraphicsScene? The app is just showing a good-old fashioned tree with text, no graphics or anything fancy other than wanting to change the magnification of the view; hence, I am thinking that switching to a graphics scene would be overkill.

Or, am I wrong, and switching to a graphics scene is the only simple way to do it?

Note a trimmed down version of the app is at Code Review. It contains a SSCCE, but is a bit long to post here.

In a site discussing how to put widgets on a scene, trolltech wrote (emphasis added):

I myself and several other Trolls’ve spent some time researching this topic [how to embed a widget in a QGraphicsScene]. It’s not trivial; most solutions to embedding widgets into a scene end up with several serious drawbacks. That’s also why Qt doesn’t have any off-the-shelf solution to this.

Widgets cannot be scaled or rotated, but graphics items can.

This suggests I cannot perform, in a simple way, the operations I want to on my QWidget by itself. That is, perhaps I need to add it to a scene, which is what I was trying to avoid. If that is the answer, then I'll accept it and start a new question if I get stuck doing that.

Note I just found this question, which is pretty much a duplicate, and does not have an (accepted) answer.

Related content

  • http://www.qtcentre.org/threads/62745-Zoom-a-view

  • QTableView Zoom In/Out

  • Drawing widgets (such as buttons) over QGraphicsView

  • QGraphicsView Zooming in and out under mouse position using mouse wheel

  • https://forum.qt.io/topic/15308/qgraphicsview-zooming-with-qslider

  • https://wiki.qt.io/Smooth_Zoom_In_QGraphicsView


回答1:


As suggested by the docs quoted from trolltech in the original question, there is no built-in method to zoom on a view.

If the goal is to avoid the use of QGraphicsViews, the simplest way to separate the size of the font on the screen, versus the size of the font saved or printed, is to basically have two fonts. One to be displayed on the screen you can call 'zoom', versus the other to be saved/printed and call that 'font size'.

I got this idea from qtcentre (in a post I added to the original post too):

http://www.qtcentre.org/threads/62745-Zoom-a-view



来源:https://stackoverflow.com/questions/30601123/zooming-a-view-in-pyqt

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