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. Path draws on Mac but not on Windows
Forum Updated to NodeBB v4.3 + New Features

Path draws on Mac but not on Windows

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 476 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
    Daniel Santos
    wrote on last edited by
    #1

    Hi,
    I have a tiny app that draws a path on a QPixmap. It works on Mac OS Big Sur. On windows 10 nothing is shown in the pixmap.
    Below is the code that builds the path, writes it to a file (the image is empty) :

    void MapDisplayArea::display() {
    
        if (!pathDrawn) {
            mapReader->reopenStream();
            QPainterPath path;
            bool stop = false;
            int lineCounter = 0;
            try {
                while (!stop) {
                    std::pair<double, double> coordPair = mapReader->getNextCoordinate();
                    lineCounter += 1;
                    double xcoord = std::get<0>(coordPair);
                    double ycoord = std::get<1>(coordPair);
                    if (xcoord == -1.0 && ycoord == -1.0) {
                        stop = false;
                        hasStarted = false;
                    } else {
                        int widgetHeight = this->size().height();
                        ycoord = (widgetHeight - ycoord - (widgetHeight + yoffset))*scale;
                        xcoord = (xcoord - xoffset)*scale;
                        if (hasStarted == false) {
                            std::cout << lineCounter<< " moveTo";
                            path.moveTo(xcoord, ycoord);
                            hasStarted = true;
                        } else {
                            std::cout << lineCounter<< " lineTo";
                            path.lineTo(xcoord, ycoord);
                        }
                    }
                }
            } catch (std::out_of_range *ex) {
                std::cout << ex->what();
            }
            std::cout << "\n" << "lines read : ";
            std::cout << lineCounter;
            QSize size = this->minimumSizeHint();
            QPixmap pixmap(size);
            pixmap.fill();
            QPainter pixmappainter(&pixmap);
            pixmappainter.drawPath(path);
            pixmap.save("C:\\temp\\worldmap.png", "PNG");
            pathDrawn = true;
    
        } else {
            if (!imagePainted) {
                QSize size = this->minimumSizeHint();
                QPixmap pixmap1("C:\\tmp\\worldmap.png");
                QPainter painter(this);
                painter.drawPixmap(0,0,size.width(), size.height(), pixmap1);
                imagePainted = true;
            }
        }
    }
    

    I have no idea why this is so.
    Thanks,
    Regards

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

      Hi,

      Your example shows two different path for the saving, is that a typo ?

      Do you mean the file is created but empty ? What happens if you explicitly set colors on your pixmap to fill it and on your painter to draw ?

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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Daniel Santos
        wrote on last edited by Daniel Santos
        #3

        @SGaist said in Path draws on Mac but not on Windows:

        the fil

        Hi,

        The logic of this code is drawing a set of lines to a pixmap, saving that pixmap, and afterwords when the method runs, it gets the image instead of redrawing the paths again.

        The problem is that the code that does the drawing produces a blank pixmap. On my mac it runs fine. On windows it doesn't.

        Thanks,
        Regards

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Daniel Santos
          wrote on last edited by
          #4

          Hi,

          I found that it is related to the scroll area where I place the pixmap that I read after the lines are drawn on a initial pixmap that is then stored on a file.
          Strangely its different on windows.

          Regards

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            What exactly happened ?

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

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Daniel Santos
              wrote on last edited by
              #6

              Hi,

              I am a bit confused. The code loads the file with the paths to draw. It draws them to the file and saves it. But it was not showing anything when the file was loaded as a pixmap and set on the QWidget that is inside the scroll area.
              Any way, I had a variable that prevented the image from being loaded more than once.
              I removed it and now it is working.

              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