How to set background for qgraphicsscene ?



  • I used Qt's GrpahicsFrame to made an application of graffiti board. In addition, I want to set background for graphicsscene by QGaphicsScene::drawPixmap(const Qpixmap &pixmap) , it's right, but now this graffiti board is no respond for my mouse, I can't draw some lines on the board. The reason why I want to set a background is hope that I can draw better based on this picture.
    if you know any other ways or suggestons, please tell me.



  • scene = new QGraphicsScene(20, 115, 600, 600,this);
    scene->setItemIndexMethod(QGraphicsScene::NoIndex);
    canvas = new CanvasItem(this);
    scene->addItem(canvas);

    graphicsView = new QGraphicsView(this);
    graphicsView->setObjectName(QStringLiteral("graphicsView"));
    graphicsView->setGeometry(QRect(20, 115, 600, 600));
    graphicsView->setMouseTracking(true);
    graphicsView->setScene(scene);
    QSizePolicy sizePolicy0 (QSizePolicy::Fixed, QSizePolicy::Fixed);
    sizePolicy0.setHorizontalStretch(0);
    sizePolicy0.setVerticalStretch(0);
    graphicsView->setSizePolicy(sizePolicy0);
    graphicsView->setFrameStyle(QFrame::Panel | QFrame::Raised);
    [QGraphicsView with QPixMap Background](https://forum.qt.io/topic/6313/qgraphicsview-with-qpixmap-background/4)
    

    According this post, I use QgraphicsView::setStyleSheet() to set background, It‘s still useless.
    but I comment this statement which "scene->addItem(canvas);", It's work.

    //class CanvasItem :public QObject, public QGraphicsItem



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.