Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Because he draws in half QPixmap & QPainter
Forum Updated to NodeBB v4.3 + New Features

Because he draws in half QPixmap & QPainter

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 857 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Domenico
    wrote on last edited by Domenico
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • D Domenico

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        D 1 Reply Last reply
        1
        • jsulmJ jsulm

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

          D Offline
          D Offline
          Domenico
          wrote on last edited by
          #4

          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?

          jsulmJ 1 Reply Last reply
          0
          • D Domenico

            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?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Domenico As written in the documentation QPainter does not guarantee to draw besides pow(2, 15) - this is the problem.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • SGaistS SGaist

              Hi,

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

              D Offline
              D Offline
              Domenico
              wrote on last edited by
              #6

              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

              jsulmJ 1 Reply Last reply
              0
              • D Domenico

                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

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Domenico Please read the link I posted...

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                D 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @Domenico Please read the link I posted...

                  D Offline
                  D Offline
                  Domenico
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    Domenico
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved