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. QPainter drawRect on QImage
Forum Updated to NodeBB v4.3 + New Features

QPainter drawRect on QImage

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 23.4k 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.
  • T Offline
    T Offline
    tclin1998
    wrote on last edited by
    #1

    Hi All:
    I have a question about drawing rectangle on monochrom QImage.

    @
    QImage _rowImg = QImage(QSize(10,10), QImage::Format_MonoLSB);
    _rowImg.fill(Qt::color0); // fill _rowImg with Qt:color0
    QPainter p;
    p.begin(imgOutline);
    // p.setCompositionMode(QPainter::RasterOp_SourceOrDestination);
    p.setPen(QPen(Qt::color1)); // use 1 to draw, the pen with is 1 pixel solid line
    p.drawRect(QRect(0,0,5,5));
    p.end();@
    // *********** END ************

    I suppose the result will be

    1111100000
    1000100000
    1000100000
    1000100000
    1111100000
    0000000000
    0000000000
    0000000000
    0000000000

    However the result is

    1111100000
    1111100000
    1111100000
    1111100000
    1111100000
    0000000000
    0000000000
    0000000000
    0000000000

    The default QBrush is 'NoBrush', My question is why the center of QRect(0,0,5,5) is filled with Qt:color1, which is not
    supposed to. Do I miss anything here?

    Thanks!

    -Todd

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DeVeL-2010
      wrote on last edited by
      #2

      Hello tclin1998,

      this works for me (Qt 4.7.2 and Windows):
      @QImage _rowImg = QImage(QSize(10,10), QImage::Format_MonoLSB);
      _rowImg.fill(Qt::color0); // fill _rowImg with Qt:color0
      QPainter p;
      p.begin(&_rowImg);
      p.setPen(QPen(QColor(Qt::color0)));
      p.setBrush(QBrush(QColor(Qt::color0), Qt::NoBrush));
      p.drawRect(QRect(0,0,5,5));
      p.drawRect(QRect(3,3,5,5));
      p.end();
      @

      But this seems a bit strange, why should color of pen be Qt::color0? And you need to set color of brush also to Wt::color0, even if you don't want any (Qt::NoBrush). However, drawing a second rectangle (as above) gives:

      1111110000
      1000010000
      1000010000
      1001111110
      1001010010
      1111110010
      0001000010
      0001000010
      0001111110
      0000000000

      Maybe there is an error in QImage and format Mono.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tclin1998
        wrote on last edited by
        #3

        BTW
        I'm using x86 Linux so it's using QImage::Format_MonoLSB should be correct.
        If I can get the answer from this forum, is there a way to let the developer take a look this problem>

        Thanks

        -Todd

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DeVeL-2010
          wrote on last edited by
          #4

          Maybe someone from Nokia will read this thread.
          You can also report it as bug in the "Qt bug tracker system":http://bugreports.qt.nokia.com/secure/Dashboard.jspa

          In my opinion there should be no difference in using QImage::Format_Mono or QImage::Format_MonoLSB when accessing the image just through Qt classes. Only when you operate on the data directly it should be important.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tclin1998
            wrote on last edited by
            #5

            This is from the 4.6.2 doc:

            Warning: Painting on a QImage with the format QImage::Format_Indexed8 is not supported
            I suppose QImage::mono is not supported either since it also uses table look up.

            -Todd

            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