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. QGraphicsView with QPixMap Background
Forum Updated to NodeBB v4.3 + New Features

QGraphicsView with QPixMap Background

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 18.2k 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.
  • E Offline
    E Offline
    evergreen
    wrote on last edited by
    #1

    Hello,

    I want to set a QPixMap as background of a QGraphicsView. I can't find a way to do it via the doc.
    Anyone knows how to preceed?

    Thanks

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      "QGraphicsScene::drawBackground()":http://doc.trolltech.com/latest/qgraphicsscene.html#drawBackground?

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • E Offline
        E Offline
        evergreen
        wrote on last edited by
        #3

        If i follow you and the doc, I've got to overload this method.
        I would do that

        @void custom_view::drawBackground(QPainter *p, const QRectF &rect)
        {
        QpixMap Background("./toto.png");
        p->drawPixmap(QRect(0, 0, width(), height()), Background);
        }
        @
        And then call it into the constructor.

        Am I right?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Franzk
          wrote on last edited by
          #4

          No, don't call it in the constructor. Just pass the scene to the view.

          You might want to cache the image, as to prevent unnecessary disk access, but that's for later I guess. You should probably learn more about the "graphics/view framework":http://doc.trolltech.com/latest/graphicsview.html.

          "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • S Offline
            S Offline
            srikanth_trulyit
            wrote on last edited by
            #5

            You can also use stylesheet (set the image of interest as border-image) and apply it on graphicsview. This can be the case if you are interested in applying the pixmap in QGraphicsPixmapItem rather than the item itself.

            1 Reply Last reply
            0
            • E Offline
              E Offline
              evergreen
              wrote on last edited by
              #6

              In fact, I thought about using stylesheets but I my case I don't know if it's possible.
              See, I don't use a file for the pixmap, but the method grabWidget which catches a widget appearance into a QPixMap. That way, I don't have a absolute path to put to the stylesheet.
              Is it possible to use the stylesheet tho?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                srikanth_trulyit
                wrote on last edited by
                #7

                Stylesheet is file agnostic. You can do
                @setStyleSheet("background-image:your_pixmap_path");@

                Else go with drawBackground.

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  evergreen
                  wrote on last edited by
                  #8

                  When you say your_pixmap_path, you talk about a real path don't you.
                  What I would like to do would be something like :

                  (this is a simplied code of course)
                  in the main window class :

                  @QMdiArea mdi;
                  setCentralWidget(mdi)
                  QPixmap pix = QPixmap::grabWidget(mdi);
                  this->setStyleSheet("background-image:" + pix);@

                  This does not work but is there a similar way to do it?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    srikanth_trulyit
                    wrote on last edited by
                    #9

                    Yes, it is real path. You can say pix.save("your_pixmap_path.png") and use it in styleSheet

                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      evergreen
                      wrote on last edited by
                      #10

                      Okay, I see what you mean.
                      I was trying to avoid dealing with saving a pixmap i have in my prog to relaod it in the stylesheet of the same prog but I guess there's no other way by using stylesheets

                      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