Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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:

    c636e2e3-f958-4434-a5a4-ecde5a51f17d-image.png

    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:

    62a280ec-9109-465c-83df-123e8ef039be-image.png

    because? what is missing? thank you very much for helping


  • Lifetime Qt Champion

    @Domenico See https://doc.qt.io/qt-5/qpainter.html
    "Limitations

    If 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."


  • Lifetime Qt Champion

    Hi,

    Because the text renderer on the forum does not seem to support it, it should be read pow(2, 15) not 215



  • 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?


  • Lifetime Qt Champion

    @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


  • Lifetime Qt Champion

    @Domenico Please read the link I posted...



  • @jsulm @SGaist

    i read, so it is not a solution as implemented in the above code? or is there another way to draw it and that all points are displayed?



  • I solved it differently, implementing with library QImage, drawing pixel by pixel, quite long but reliable implementation code. thanks anyway. regards


Log in to reply