QGraphicsView缩放与windowsize [英] QGraphicsView scale with windowsize

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

问题描述

我正在创建一个可轻松创建测验的应用程序,以便以后在投影机上显示。我计划使用QGraphicsView和QGraphicsScene显示屏幕。

I'm creating an application with as purpose easily creating a quiz to later display on a projector. I was planning on using a QGraphicsView and QGraphicsScene to display the screen.

我想知道如何(如果可能的话)我可以使场景的固定大小,使视图总是显示整个场景。也就是说如果窗口大小改变并且graphicsView被调整大小,则场景被显示为与其他大小相同,但是然后缩放。我试过搞砸QGraphicsView :: fitInView和Rectangles,但没有真正的工作。

I am wondering how (if it is possible at all) I can make the scene a fixed size, so that the view will always display the whole scene. I.e. if the window size is changed and the graphicsView is resized, the scene is displayed identical to other sized, but then scaled. I have tried messing around with the QGraphicsView::fitInView and the Rectangles, but nothing really worked out.

如果有另一个数据结构更适合我的需要,

If there is another data structure which is more suited for my needs, I'm very open for suggestions!

推荐答案

您可以在QGraphicsView中重新实现resizeEvent(QResizeEvent * event),如:

You can reimplement resizeEvent( QResizeEvent *event ) in your QGraphicsView like:

void MyView::resizeEvent(QResizeEvent *event)
{

    fitInView(0, 0, 500, 500,Qt::KeepAspectRatio);

    QGraphicsView::resizeEvent(event);
}

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

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