Drawing a rectangle

  • I need to draw transparent rectangles on a blank image. Is there a way to do it more efficiently than what I already have?

    QImage img(this->size, QImage::Format_ARGB32);
    QPainter painter(&img);
    int size = tileSize - overLap;
    for (int i = 0; i < isShown.size(); i++) {
        for (int j = 0; j < isShown[i].size(); j++) {
            if (needToPaint(i,j)) {
                QColor color(getScore(i,j)*255,0,0);
                QRect dest = QRect(j*(size), i*(size), size, size);
                QPainterPath path;
                painter.fillPath(path, color);

  • Qt Champions 2017

    QPainter::drawRect is probably a tad more efficient, but there might be other viable ideas depending on your data. For example you could paint opaque only instead of using transparency, as you already know what the background color is ...

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.