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. [SOLVED]Drawing a background with a pixmap and then drawing another pixmap on the background with QGraphicsItem
Qt 6.11 is out! See what's new in the release blog

[SOLVED]Drawing a background with a pixmap and then drawing another pixmap on the background with QGraphicsItem

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.6k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    So here's what I want to do. I have a QGraphicsScene and I want to add a custom QGraphicsItem object to it. That QGraphicsItem is rectangle shaped. I want to add a .png picture as a background to that recangle and then I want to add another .png picture on that background. So, I use QPainter. Doing the background like this works

    painter->setBrush(QBrush(QPixmap(":/pictures/background.png")));

    but the problem is that the background.png picture is large and the rectangle is small, so only a small portion is painted to the rectangle shape. Is there a way to automatically resize/scale the .png picture, so it fits into the rectangle? Then the other issue. I'm trying to draw the second .png picture on the background like this:

    painter->drawPixmap(0,0,30,30,QPixmap(":/pictures/figure.png"));

    but once again, the picture is larger than the rectangle. The picture is mostly transparent, with an actual shaped picture in the middle, so I can't actually even see the picture being drawn on to the rectangle.

    Am I in the right direction with what I want to do? Can I have the images automatically resized so that they fit into any shaped rectangle? Can I draw another pixmap in the background pixmap the way I described?

    Edit:: That's indeed possible with the scaled function of QPixmap

    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