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. Problem with two stage painting
Forum Updated to NodeBB v4.3 + New Features

Problem with two stage painting

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 362 Views 2 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.
  • P Offline
    P Offline
    Perdrix
    wrote on 25 Aug 2020, 14:07 last edited by Perdrix
    #1

    In my CTOR I coded:

    setBackgroundRole(QPalette::Dark);      // A darker background please
        setAutoFillBackground(true);
    

    And then in the paintEvent method:

    QPainter pixPainter(&m_drawingPixmap);
        pixPainter.initFrom(this);
        pixPainter.setRenderHint(QPainter::Antialiasing);
        pixPainter.setRenderHint(QPainter::SmoothPixmapTransform);
        pixPainter.eraseRect(rect());
    
           // lots of code writing to pixmap
    
        pixPainter.end();
    
        QPainter painter(this);
        painter.drawPixmap(0, 0, m_drawingPixmap);
        painter.end();
    

    which worked fine.

    I cranked up the error level to /W3, and I was told to change pixPainter.initFrom(this), to pixPainter.begin()

    BUT when I made that change, the background colour changed from the nice mid-grey to a nasty glary white.

    So, was the warning correct and if so how do I get my grey background back?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 25 Aug 2020, 18:21 last edited by
      #2

      Hi,

      Because your should explicitly setup the pen/brush of your painter.

      Out of curiosity, why that two stage painting ? You are doing all your operation on that QPixmap that is the exact size of your widget and then painting it on that widget at the exact same size. You could do the painting directly on your widget.

      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
      • P Offline
        P Offline
        Perdrix
        wrote on 25 Aug 2020, 21:14 last edited by
        #3

        Because there'll be other stuff writing onto that pixmap so I'm preparing for double buffering it all.

        explicitly set pen/brush

        I don't want to manually set a background brush - I want inherit the dark scheme palette, hence the call to setBackgroundRole(QPalette::Dark);

        If that's not the right way in Qt5 (I lifted that code from a Qt 4 book), how should I do it.

        Thanks

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Perdrix
          wrote on 26 Aug 2020, 08:58 last edited by Perdrix
          #4

          I tried this:

                  QPainter pixPainter(&m_drawingPixmap);
                  QPalette palette{ QGuiApplication::palette() };
                  QBrush brush{ palette.dark() };
              
                  pixPainter.setRenderHint(QPainter::Antialiasing);
                  pixPainter.setRenderHint(QPainter::SmoothPixmapTransform);
                  pixPainter.fillRect(rect(), brush);
              
          

          Which works, but shouldn't setBackgroundRole work too?

          David

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 26 Aug 2020, 18:39 last edited by
            #5

            That's for your widget which your pixmap has no relation with technically speaking.

            Personally I am used to explicitly setup the painter so it's not something that "shocks" me.

            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

            1/5

            25 Aug 2020, 14:07

            • Login

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