Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8116791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:56:32+00:00 2026-06-06T03:56:32+00:00

In a QGraphicsScene , I have a background set with a few QGraphicsItem s

  • 0

In a QGraphicsScene, I have a background set with a few QGraphicsItems on top of it. These graphics items are of arbitrary shape. I’d like to make another QGraphicsItem, i.e. a circle, which when placed over these items will essentially show the background within this circle, instead of being filled with a color.

It would sort of be like having a background with multiple layers on top of it in photoshop. Then, using a circular marquee tool to delete all the layers on top of the background to show the background within the circle.

Or, another way to view it could be to have an opacity set, but this opacity affects items directly underneath it (but only within the ellipse) to show the background.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:56:34+00:00Added an answer on June 6, 2026 at 3:56 am

    The following might work. It basically extends a normal QGraphicsScene with the ability to only render its background to any QPainter. Then, your “cut out” graphics item just renders the scene background over top of the other items. For this to work, the cut out item would have to have the highest Z-value.

    screen shot

    #include <QtGui>
    
    class BackgroundDrawingScene : public QGraphicsScene {
    public:
      explicit BackgroundDrawingScene() : QGraphicsScene() {}
      void renderBackground(QPainter *painter,
                            const QRectF &source,
                            const QRectF &target) {
        painter->save();
        painter->setWorldTransform(
              QTransform::fromTranslate(target.left() - source.left(),
                                        target.top() - source.top()),
              true);
        QGraphicsScene::drawBackground(painter, source);
        painter->restore();
      }
    };
    
    class CutOutGraphicsItem : public QGraphicsEllipseItem {
    public:
      explicit CutOutGraphicsItem(const QRectF &rect)
        : QGraphicsEllipseItem(rect) {
        setFlag(QGraphicsItem::ItemIsMovable);
      }
    protected:
      void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) {
        BackgroundDrawingScene *bgscene =
            dynamic_cast<BackgroundDrawingScene*>(scene());
        if (!bgscene) {
          return;
        }
    
        painter->setClipPath(shape());
        bgscene->renderBackground(painter,
                                  mapToScene(boundingRect()).boundingRect(),
                                  boundingRect());
      }
    };
    
    
    int main(int argc, char **argv) {
      QApplication app(argc, argv);
    
      BackgroundDrawingScene scene;
      QRadialGradient gradient(0, 0, 10);
      gradient.setSpread(QGradient::RepeatSpread);
      scene.setBackgroundBrush(gradient);
    
      scene.addRect(10., 10., 100., 50., QPen(Qt::SolidLine), QBrush(Qt::red));
      scene.addItem(new CutOutGraphicsItem(QRectF(20., 20., 20., 20.)));
    
      QGraphicsView view(&scene);
      view.show();
    
      return app.exec();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a QGraphicsScene with about 1000 QGraphicsItems, which are actually physics items. Each
I want to make something like a hud. I have a QGraphicsScene with a
Since most of the convenience functions of QGraphicsScene and QGraphicsItem (such as items(), collidingItems(),
I have a QGraphicsView and a QGraphicsScene connected like this: graphicsScene->setSceneRect(this->graphicsView->rect()); graphicsView->setScene(this->Scene); Then I
I have created a class Atom that extends the Qt class QGraphicsItem like this:
I have a QGraphicsScene where the order of the items is very important. I'd
I have a QGraphicsScene in which I add a QGraphicsItem. Inside the QGraphicsItem, I
I have a matrix of QGraphicsItem's in a QGraphicsScene and when I click an
I inherited my scene from QGraphicsScene. I add many items(QGraphicslineItem, QGraphicsItem, QGraphicsTextItem) on this
I have a QGraphicsScene on which I would like to draw some special curves.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.