从Qt的选定区域(QRubberBand)截图 [英] Taking a screenshot from the selected area(QRubberBand) on Qt
问题描述
我正在尝试创建一个Qt应用程序从屏幕上的选定区域截取屏幕截图。现在我使用QRubberBand选择屏幕的一个区域。
I am trying to create a Qt application to take screenshot from the selected area on screen. For now I am using QRubberBand to select an area of the screen. It works like this.
- 当Capture按钮单击时,会显示一个覆盖透明小部件(全屏,但没有框架) li>
- 我使用QRubberBand在透明窗口小部件上选择一个区域。
我想我必须将从选择QRubberBand得到的尺寸传递给这个:
I am thinking I have to pass the dimensions I get from selecting the QRubberBand to this:
screen-> grabWindow(WId window,int x = 0,int y = 0,int width = -1,int height = -1);
那么如何从QRubberBand获取我需要的信息?
我被困在这里,所以有人请帮助我!
So how do I get the info I need from the QRubberBand? I am stuck here, so someone please help me!
推荐答案
在 OnMouseRelease
事件中, code> QRubberBand 使用 geometry()
。接下来使用 QRect :: getRect
,您可以将矩形左上角的位置提取为x和y,将其尺寸提取为width和height。 :
In your OnMouseRelease
event you can get the rect of the QRubberBand
using geometry()
. Next using the QRect::getRect
you can extract the position of the rectangle's top-left corner to x and y, and its dimensions to width and height. :
const QRect & selectRect = mRubberBand->geometry();
int x, y, width, height;
selectRect.getRect(&x, &y, &width, &height);
这篇关于从Qt的选定区域(QRubberBand)截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!