Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to set background for qgraphicsscene ?
Qt 6.11 is out! See what's new in the release blog

How to set background for qgraphicsscene ?

Scheduled Pinned Locked Moved General and Desktop
qt5.4qgraphicsviewqgraphicsscene
2 Posts 1 Posters 4.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    happyRoll
    wrote on last edited by happyRoll
    #1

    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.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      happyRoll
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved