在 PyQt 中缩放视图? [英] Zooming a view in PyQt?

查看:54
本文介绍了在 PyQt 中缩放视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的树形应用程序,它在 QMainWindow 内显示一个 QTreeView. 我想让用户能够更改内容的放大级别(最有可能使用旋转框),但实际上并未更改文本的底层字体大小.

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.

有没有办法在不将我的整个应用程序更改为 QGraphicsScene 的情况下做到这一点?该应用程序只是显示一个带有文本的老式树,没有图形或任何花哨的东西,只是想改变视图的放大率;因此,我认为切换到图形场景会有点矫枉过正.

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?

注意精简版应用 正在代码审查中.它包含一个 SSCCE,但在这里发布有点长.

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

在一个讨论 如何将小部件放在场景中,trolltech 写道(强调):

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

我自己和其他几个巨魔花了一些时间研究这个主题 [如何在 QGraphicsScene 中嵌入小部件].这不是微不足道的;大多数将小部件嵌入场景的解决方案最终都有几个严重的缺点.这也是为什么 Qt 没有现成的解决这个问题.

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.

小部件不能缩放或旋转,但图形项可以.

这表明我无法以简单的方式在我的 QWidget 上单独执行我想要的操作.也就是说,也许我需要将它添加到场景中,这是我试图避免的.如果这就是答案,那么我会接受它并开始一个新问题,如果我坚持这样做.

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.

相关内容

QTableView 放大/缩小

在 QGraphicsView 上绘制小部件(例如按钮)

QGraphicsView 放大和使用鼠标滚轮在鼠标位置下方

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

https://wiki.qt.io/Smooth_Zoom_In_QGraphicsView

推荐答案

正如原始问题中从 trolltech 引用的文档所建议的那样,没有内置的方法来放大视图.

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

如果目标是避免使用 QGraphicsViews, 将屏幕上的字体大小与保存或打印的字体大小分开的最简单方法是基本上有两个字体.一个显示在屏幕上,您可以称为缩放",而另一个要保存/打印并称为字体大小".

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'.

我从 qtcentre 得到了这个想法(在我添加到原始帖子的帖子中):

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

http://www.qtcentre.org/threads/62745-Zoom-视图

这篇关于在 PyQt 中缩放视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆