public void first() {
    // ! [0]
    QGraphicsScene scene = new QGraphicsScene();
    scene.addText("Hello, world!");

    QGraphicsView view = new QGraphicsView(scene);
    view.show();
    // ! [0]
  }
  public void fourth() {

    // ! [4]
    QGraphicsScene scene = new QGraphicsScene();
    QGraphicsView view = new QGraphicsView(scene);
    view.show();

    // a white semi-transparent foreground
    scene.setForegroundBrush(new QBrush(new QColor(255, 255, 255, 127)));

    // a grid foreground
    scene.setForegroundBrush(new QBrush(QColor.lightGray, Qt.BrushStyle.CrossPattern));
    // ! [4]
  }
  public void third() {

    // ! [3]
    QGraphicsScene scene = new QGraphicsScene();
    QGraphicsView view = new QGraphicsView(scene);
    view.show();

    // a blue background
    scene.setBackgroundBrush(new QBrush(QColor.blue));

    // a gradient background
    QRadialGradient gradient = new QRadialGradient(0, 0, 10);
    gradient.setSpread(QGradient.Spread.RepeatSpread);
    scene.setBackgroundBrush(new QBrush(gradient));
    // ! [3]
  }
  public void second() {

    // ! [1]
    QGraphicsScene scene = new QGraphicsScene();
    scene.addRect(0d, 0d, 50d, 50d);
    QPrinter printer = new QPrinter(QPrinter.PrinterMode.HighResolution);
    printer.setPageSize(QPrinter.PageSize.A4);

    QPainter painter = new QPainter(printer);
    scene.render(painter);
    // ! [1]

    int depth = 0;

    // ! [2]
    QSizeF segmentSize = sceneRect().size().divide(java.lang.Math.pow(2, depth - 1));
    // ! [2]
  }
  public OpenGLInGraphicsView(boolean gl) {
    QGLFormat format = new QGLFormat();
    format.setSampleBuffers(true);

    if (gl) {
      setViewport(new QGLWidget(format));
      setWindowTitle("GL window");
    } else {
      setWindowTitle("Non GL Window");
    }

    QGraphicsScene scene = new QGraphicsScene();

    QGraphicsPixmapItem pixmapItem =
        new QGraphicsPixmapItem(new QPixmap("classpath:org/qtjambi/images/chip-demo.png")) {

          @Override
          public void paint(QPainter painter, QStyleOptionGraphicsItem option, QWidget widget) {
            // painter.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform, true);
            // super.paint(painter, option, widget);
            painter.drawPixmap(boundingRect().toRect(), this.pixmap());
          }
        };
    pixmapItem.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsMovable, true);
    pixmapItem.setTransformationMode(Qt.TransformationMode.SmoothTransformation);
    scene.addItem(pixmapItem);

    QGraphicsPixmapItem otherPixmapItem =
        scene.addPixmap(new QPixmap("classpath:org/qtjambi/images/chip-demo.png"));
    otherPixmapItem.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsMovable, true);
    otherPixmapItem.setTransformationMode(Qt.TransformationMode.SmoothTransformation);

    scene.addText("Hello World").setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsMovable, true);

    setScene(scene);
    rotate(45);

    setRenderHint(QPainter.RenderHint.SmoothPixmapTransform);

    // setRenderHint(QPainter.RenderHint.Antialiasing, true);
    // setRenderHint(QPainter.RenderHint.HighQualityAntialiasing, true);
    // setRenderHint(QPainter.RenderHint.TextAntialiasing, true);
  }