Important: Please read the 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();
    QPixmap pix1(100000,40);
    QPainter paint1(&pix1);
    //coordinate Y1
            paint1.setFont(QFont("Segoe UI",6,QFont::Bold));
            paint1.setFont(QFont("Segoe UI",6,QFont::Bold));
    //coordinate X1
            int addCordX1 = 9;
            paint1.setFont(QFont("Segoe UI",6,QFont::Bold));
            for(int i = 0; i < 100000; i++)
    QGridLayout *GLayout = new QGridLayout();
    GLayout->addWidget(new QLabel("M1"),0,1);
    QWidget *widget = new QWidget();
    widget ->setLayout(GLayout);
    QGraphicsScene *scene = new QGraphicsScene();
    QGraphicsView *view = new QGraphicsView();
    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

  • Lifetime Qt Champion

    @Domenico See

    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


    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