创建透明的QPixmap

时间:2013-07-29 08:05:04

标签: c++ qt qt4 pyqt background-color

我在QPixmap上使用QPainter作为绘画框架。 QGraphicsScene持有QPixmap。这幅画效果很好。但问题是,当我更改QGraphicsView的背景颜色时,它不会反映在屏幕上。我试过QPixmap :: fill(Qt :: tranparent)。但它没有用。

如何实现这种透明的QPixmap? Thanx提前?

int main(int argc, char **argv){

QApplication a(argc, argv);

QMainWindow *win = new QMainWindow();
win->resize(600,600);
win->move(80,80);
win->show();


QGraphicsScene *scene = new QGraphicsScene(win);
QGraphicsView view(scene,win);
view.resize(590,590);
view.setBackgroundBrush(QColor(rand()%255,rand()%255, rand()%255, 255));
view.show();

QPixmap *pix = new QPixmap(600,600);
pix->fill(&view,QPoint(0,0));
QGraphicsPixmapItem *item = scene->addPixmap(*pix);

QPainter *painter = new QPainter(pix);


int count=10;
while(count){

    painter->setPen((*new QColor(rand()%255,rand()%255, rand()%255, 255)));
    painter->setBrush(QColor(rand()%255,rand()%255, rand()%255, 255));
    painter->drawRect(rand()%300, rand()%300, rand()%300, rand()%300);


    item->setPixmap(*pix);
    a.processEvents(0x00);
    count--;

}


return a.exec();

}

0 个答案:

没有答案