Scalable painting of a Qt application

徘徊边缘 提交于 2019-12-01 23:50:08

问题


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.


回答1:


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.




回答2:


Bit of a guess here as I've not tried it... but you could try putting the top-level widget into a QGraphicsView then get the QGraphicsView to do the scaling. You could then enable OpenGL on the QGraphicsView and have it scaled in hardware so it's nice and fast.



来源:https://stackoverflow.com/questions/1499062/scalable-painting-of-a-qt-application

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