QT之QDirectPainter使用

来源:互联网 发布:白金数据 电影天堂 编辑:程序博客网 时间:2024/06/05 10:09

为了在嵌入式上解决界面刷新闪烁问题,QT提出了两种解决方案:

1、对控件设置Qt::WA_PaintOnScreen

Indicates that the widget wants to draw directly onto the screen. Widgets with this attribute set do not participate in composition management, i.e. they cannot be semi-transparent or shine through semi-transparent overlapping widgets. Note: This flag is only supported on X11 and it disables double buffering. On Qt for Embedded Linux, the flag only works when set on a top-level widget and it relies on support from the active screen driver. This flag is set or cleared by the widget's author. To render outside of Qt's paint system, e.g., if you require native painting primitives, you need to reimplement QWidget::paintEngine() to return 0 and set this flag.

2、使用QDirectPainter直接在Framebuffer上绘图

QDirectPainter支持3种模式,一般我们使用NonReserved即可:

QDirectPainter mPainter(this)

QDirectPainter::lock();

mPainter.setRegion(requsteRegion);

QRegion allocatedregion=mPainter.allocatedRegion();

mPainter.startPainting();

//结合allocatedregion在QDirectPainter::framebuffer()指向的缓存中直接绘图。

mPainter.endPainting();

QDirectPainter::unlock();

需要注意allocatedRegion返回值

QRegion QDirectPainter::allocatedRegion () const

Returns the currently reserved region.

Note that if the QDirectPainter::Reserved flag is set, the region returned by this function will always be equivalent to the region returned by the requestedRegion() function. Otherwise they might differ (see Dynamic Allocation for details).


对于LCD分辨率640*480的显示器来说,居中有一个大小为100*100的window,当setRegion一般传入640*480后,allcatedRegion会返回一个QRegion,这个QRegion包括4个Rect,用于表明除中间100*100外的LCD其他区域。 (前提条件是window必须有focus)


在项目的应用中,我需要一个窗口显示摄像头采集到的视频图像,并且尽快实时刷新,此窗口有标题栏用于显示状态。同时,一定条件下,需要在视频上弹出一个对话框但不能影响不被对话框遮挡的区域的视频刷新。方法如下:

建立一个Window和Dialog,Window作为主UI,并建立定时器。

定时器实时获取AllocatedRegion后,将摄像头的数据直接刷新到FrameBuffer上。

当Dialog没有显示时,视频的刷新区域是除Window外的所有屏幕区域。

当Dialog显示时,视频的刷新区域还要减去Dialog的显示区域。

0 0
原创粉丝点击