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]
  }