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

Path draws on Mac but not on Windows



  • 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


  • Lifetime Qt Champion

    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 ?



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



  • 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


  • Lifetime Qt Champion

    What exactly happened ?



  • 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


Log in to reply