Add a border to a QPixmap

橙三吉。 提交于 2019-12-12 04:39:09

问题


I load a QPixmap from a file. I want to add a border around the QPixmap, say 4px white on each side.

What is the fastest way to do this? Do I have to create a second larger QPixmap and draw the first into the second or is there some way to extend the existing one without scaling (I've noticed that there is a QPixmap::transformed() but don't know if this is suitable in my case.


回答1:


Do I have to create a second larger QPixmap and draw the first into the second

Yes.

is there some way to extend the existing one without scaling

Yes. The larger pixmap will take an unscaled copy of the original one.

The foregoing assumes that you care about the resulting pixmap. If you don't care about it, but only care to display the pixmap on a window/widget with some border, then simply draw the border and pixmap separately using QPainter, OpenGL geometry, etc.



来源:https://stackoverflow.com/questions/45865524/add-a-border-to-a-qpixmap

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