Unsolved Because he draws in half QPixmap & QPainter
-
hello everyone,
can you help me on this problem, I created a graph that allows you to draw the X and Y coordinates and draw so that it reaches the full length of 100000, but in the following code it does not draw it for the whole 100000 line but goes up to 32850, what's wrong? the code is:QLabel *lbl1 = new QLabel(); lbl1->setFixedSize(100000,40); QPixmap pix1(100000,40); pix1.fill(Qt::transparent); QPainter paint1(&pix1); //coordinate Y1 paint1.setFont(QFont("Segoe UI",6,QFont::Bold)); paint1.drawText(0,7,"1"); paint1.setFont(QFont("Segoe UI",6,QFont::Bold)); paint1.drawText(0,23,"0"); paint1.drawLine(7,2,7,27); //coordinate X1 int addCordX1 = 9; paint1.drawLine(0,26,100000,26); paint1.setFont(QFont("Segoe UI",6,QFont::Bold)); paint1.drawText(100000,34,QString::number(100000)); paint1.setPen(QPen(Qt::red,1)); for(int i = 0; i < 100000; i++) { paint1.drawRect(addCordX1,2,1,23); addCordX1++; } paint1.end(); lbl1->setPixmap(pix1); QGridLayout *GLayout = new QGridLayout(); GLayout->addWidget(new QLabel("M1"),0,1); GLayout->addWidget(lbl1,0,2); QWidget *widget = new QWidget(); widget ->setLayout(GLayout); QGraphicsScene *scene = new QGraphicsScene(); QGraphicsView *view = new QGraphicsView(); view->setWindowTitle("Graphics..."); scene->addWidget(widget); view ->setBackgroundBrush(QBrush("#f0f0f0",Qt::SolidPattern)); view ->setScene(scene); view ->setAlignment(Qt::AlignTop | Qt::AlignLeft); view ->show();
the initial part draws perfectly like the following graph:
but then it stops up to here at point 32850 and doesn't continue to display the rest until point 100000 or maybe it didn't draw it, like the following chart:
because? what is missing? thank you very much for helping
-
@Domenico See https://doc.qt.io/qt-5/qpainter.html
"LimitationsIf you are using coordinates with Qt's raster-based paint engine, it is important to note that, while coordinates greater than +/- 215 can be used, any painting performed with coordinates outside this range is not guaranteed to be shown; the drawing may be clipped. This is due to the use of short int in the implementation."
-
Hi,
Because the text renderer on the forum does not seem to support it, it should be read
pow(2, 15)
not215
-
Hi @jsulm,
I thought it had something to do with QPixmap instead of QPainter, because trying with QPicture instead of QPixmap draws all the points. but QPicture is not suitable for my code I would need QPixmap and I don't know what the problem is, is there another way?
-
@Domenico As written in the documentation QPainter does not guarantee to draw besides pow(2, 15) - this is the problem.
-
Hi @SGaist ,
sorry for my misunderstanding, what do you mean it should be read for pow (2,15), can you give me an example? thank you very much
-
@Domenico Please read the link I posted...
-
-
I solved it differently, implementing with library QImage, drawing pixel by pixel, quite long but reliable implementation code. thanks anyway. regards