I draw a number of lines with certain shapes on the GraphicsView. I need to reduce and increase the entire scene, but at the same time it is necessary to leave the line thickness unchanged. When I do as in this example on the line, the line becomes almost invisible. It must be always the same thickness. Maybe someone will tell or direct on the correct solution of this problem?

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), scene_(new QGraphicsScene()) { ui->setupUi(this); ui->graphicsView->setScene(scene_); scene_->addLine(0, 0, 300, 100); ui->graphicsView->scale(0.1, 0.1); } 
  • one
    A little to the side of the question topic - if you draw a polyline from a pile of individual lines, causing addLine many times, the performance will be very bad. It is better to draw through QPainerPath/QPolygon - Bearded Beaver

1 answer 1

You need to draw an object with a pen with the Cosmetic attribute attached. In your case, something like this:

 QPen pen; pen.setCosmetic(true); scene_->addLine(0, 0, 300, 100, pen); ui->graphicsView->scale(0.1, 0.1);