Qt 应用程序的可扩展绘制 [英] Scalable painting of a Qt application

查看:68
本文介绍了Qt 应用程序的可扩展绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写嵌入式设备屏幕的模拟(其中包含主 QWidget 顶部的自定义小部件),虽然屏幕的原始尺寸为 800x600,但我希望能够将其放大和缩小拖动窗口的角落.如果不使用网格布局和担架(不会放大/缩小字体),我该如何完成这种缩放?我认为解决方案的一部分可能是创建一个 QTransform 并以某种方式将其注入整个应用程序的 QWidget,或其 QPaintDevice 或 QPaintEngine.我想这样做而不将 QTransform 放在每个自定义小部件中,只是主窗口"QWidget.

解决方案

这是可能的如果您正在使用 QGraphicsView 作为您的主要显示小部件.QGraphicsScene 现在支持将小部件作为内容,因此您可以直接缩放它们.>

我认为另一种方法是为每个小部件重新实现paint(),并在绘制子小部件之前手动设置变换/缩放.

I'm writing a simulation of an embedded device's screen (which contains custom widgets on top of a main QWidget), and while the native size of the screen is 800x600, I want to be able to scale it up and down by dragging the window's corner. Without diddling with grid layouts and stretchers (which won't scale the fonts up/down), how do I accomplish this sort-of zoom? I think part of the solution might be to create a QTransform and somehow inject that into the QWidget for the entire application, or its QPaintDevice or QPaintEngine. I'd like to do this without putting QTransform in each custom widget, just the "main window" QWidget.

解决方案

This is possible if you are using QGraphicsView as your main display widget. QGraphicsScene now supports widgets as content, so you can literally just scale them.

I believe the alternative is to reimplement the paint() for each widget, and manually set the transform/scale before the painting of child widgets.

这篇关于Qt 应用程序的可扩展绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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