Chinaunix首页 | 论坛 | 博客
  • 博客访问: 89682
  • 博文数量: 44
  • 博客积分: 1920
  • 博客等级: 上尉
  • 技术积分: 490
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-06 09:13
文章分类

全部博文(44)

文章存档

2011年(1)

2009年(43)

我的朋友

分类: C/C++

2009-07-09 11:00:26

QRegion:
The QRegion class specifies a clip region for a painter.
QRegion is used with QPainter::setClipRegion() to limit the paint area to what needs to be painted. There is also a QWidget::repaint() function that takes a QRegion parameter. QRegion is the best tool for reducing flicker.
A region can be created from a rectangle, an ellipse, a polygon or a bitmap. Complex regions may be created by combining simple regions using united(), intersected(), subtracted(), or xored() (exclusive or). You can move a region using translate().
You can test whether a region isEmpty() or if it contains() a QPoint or QRect. The bounding rectangle can be found with boundingRect().
The function rects() gives a decomposition of the region into rectangles.
Example of using complex regions:
void MyWidget::paintEvent(QPaintEvent *)
{
QRegion r1(QRect(100, 100, 200, 80), // r1: elliptic region
QRegion::Ellipse);
QRegion r2(QRect(100, 120, 90, 30)); // r2: rectangular region
QRegion r3 = r1.intersected(r2); // r3: intersection
QPainter painter(this);
painter.setClipRegion(r3);
... // paint clipped graphics
}

void QPainter::setClipRegion ( const QRegion & region, Qt::ClipOperation operation = Qt::ReplaceClip )
Sets the clip region to the given region using the specified clip operation. The default clip operation
is to replace the current clip region.
Note that the clip region is given in logical coordinates.

相关的英语单词:
clip:
栽剪,修剪

decomposition:
分解, 溶解, 还原(作用)腐烂, 解体
衰[蜕变
消瘦; 虚弱

例程:
#include
#include
#include
#include
class MyMainWindow:public QWidget
{
public:
MyMainWindow(QWidget *parent = 0);
private:
void paintEvent(QPaintEvent *);
QPainter *paint;
};
void MyMainWindow::paintEvent(QPaintEvent *) //paintEvent函数由系统自动调用,用不着我们人为的去调用。
{
QRegion r1(QRect(100, 100, 200, 80),QRegion::Ellipse); // r1: elliptic region
QRegion r2(QRect(100, 120, 90, 30)); // r2: rectangular region
QRegion r3 = r1.intersected(r2); // r3: intersection
paint=new QPainter;
paint->begin(this);
paint->setPen(QPen(Qt::blue,4,Qt::DashLine)); //设置画笔形式
paint->setBrush(QBrush(Qt::red,Qt::SolidPattern)); //设置画刷形式
paint->setClipRegion(r3); // paint clipped graphics
paint->drawRect(QRect(100,100,200,80));
paint->drawRect(QRect(100,120,90,30));
paint->end();
}
MyMainWindow::MyMainWindow(QWidget *parent):QWidget(parent)
{
setGeometry(100,100,300,300);
}
int main(int argc,char **argv)
{
QApplication a(argc,argv);
MyMainWindow w;
w.show();
return a.exec();
}
输出结果:
阅读(2861) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~