How Can I add image in the background of my application?
Say, I am drawing a QGraphicsItem in a QGraphicsScene and I want to add some background from an image( may be svg or png). And the background can be plain or tiled using the image.
Thank You
How Can I add image in the background of my application?
Say, I am drawing a QGraphicsItem in a QGraphicsScene and I want to add some background from an image( may be svg or png). And the background can be plain or tiled using the image.
Thank You
in your graphicsView class use
Qt Code:
To copy to clipboard, switch view to plain text mode
also
setCacheMode(CacheBackground); //makes better view
"Behind every great fortune lies a crime" - Balzac
Do you mean the background of your whole application or of your QGraphicsView?
I meant background of the whole application.
I implemented the drawBackGround() virtual function of QGraphicsScene:
void GraphicsScene::drawBackground(QPainter* painter, const QRectF &rect){
QSvgRenderer* m_renderer = new QSvgRenderer(m_gameTheme->current());
QPixmap pix;
pix = QPixmap(sceneRect().size().toSize());
pix.fill(Qt::transparent);
m_renderer->render(painter,"BackGround");
painter->drawPixmap(0,0,pix);
}
But, the in the output I saw that the whole Screen is not covered. I found, (0,0) is not right from the corner. What Should be the problem?
Mahfuz
If you want a background for the whole application you need to set it on your QMainWindow. If it should only be for the view use QGraphicsView, because QGraphicsScene is only a part of the view!
--> QGraphicsView::drawBackground().
I have implemented the same funcation for QGraphicsView, but got the same output in both case.
Bookmarks