关于QGraphicsView里使用QGraphicsScene背景图片平铺的问题

来源:互联网 发布:vx是什么聊天软件 编辑:程序博客网 时间:2024/05/22 16:50


在QGraphicsView里默认显示QGraphicsScene的时候是平铺的,如果图片尺寸过小就会平铺,如果大于QGraphicsView的尺寸,就会自动填充。

后来试了试,找到了解决方法,分享一下:

1.QGraphicsView设置一下显示位置

ui->graphicsView->setAlignment(Qt::AlignLeft | Qt::AlignTop);//这里是左上角方式显示


2.光设置1是不行的,还要设置QGraphicsScene。

重新QGraphicsScene的drawBackground函数。

void QFormScene::drawBackground ( QPainter * painter, const QRectF & rect ){    painter->drawImage(0,0, *mBkgImage);}
1.2都要设置,只setAlignment但是不重新drawBackground 没有用;只重写drawBackground 但不设置setAlignment也没有用。



原创粉丝点击