C++ 创建透明QPixmap

C++ 创建透明QPixmap,c++,qt,qt4,pyqt,background-color,C++,Qt,Qt4,Pyqt,Background Color,我使用QPixmap上的QPainter作为绘画框架。而Qgraphicscene持有QPixmap。这幅画画得很好。但问题是,当我改变QGraphicsView的背景色时,它不会反映在屏幕上。我尝试使用QPixmap::fill(Qt::tranparent)。但它不起作用 如何实现这种透明的QPixmap? 提前吃点什么 int main(int argc, char **argv){ QApplication a(argc, argv); QMainWindow *win = new

我使用QPixmap上的QPainter作为绘画框架。而Qgraphicscene持有QPixmap。这幅画画得很好。但问题是,当我改变QGraphicsView的背景色时,它不会反映在屏幕上。我尝试使用QPixmap::fill(Qt::tranparent)。但它不起作用

如何实现这种透明的QPixmap? 提前吃点什么

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();

}

不太清楚为什么你被否决了,尽管你的代码有这样一行:pix->fill(&view,QPoint(0,0));据我在文档中看到的,QPixmap中没有采用两个参数的函数。这是fill:void fill(常量QColor&color=Qt::white)的定义。您的代码实际编译了吗?尝试过pix.fill(Qt::transparent)?@Merlin069这仅适用于Qt5。Qt4包含
QPixmap::fill(const-QWidget*widget,const-QPoint&offset)
函数。它是:您想要透明项(对其他项透明)还是透明图形视图(整个小部件)?