Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unexpected colour when displaying a pixmap
Qt 6.12 LTS is out! See what's new in the release blog

Unexpected colour when displaying a pixmap

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 556 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    I ran the following code in the debugger with breakpoint set on the first pen.setColor call.

    if (stars[i].m_bAdded)
    	pen.setColor(qRgba(0, 0, 255, m_bCometMode ? 255 * 0.5 : 255));
    else
    	pen.setColor(qRgba(0, 190, 0, m_bCometMode ? 255 * 0.5 : 255));
    
    painter.drawEllipse(rc);
    

    the breakpoint was never hit.

    Putting the breakpoint on the second pen.setColor was hit many times (for every star).

    So I know that the colour used to draw the ellipse should be green.

    The pixmap is built and then written to the screen in the paintEvent handler:

    	void EditStars::paintEvent([[maybe_unused]] QPaintEvent* event)
    	{
    		QPainter painter(this);
    		drawOnPixmap();
    		//
    		// Draw the stuff we drew onto the working pixmap onto the screen
    		//
    		painter.setBackgroundMode(Qt::TransparentMode);
    		painter.drawPixmap(0, 0, pixmap);
    
    		painter.end();
    	}
    

    So why are all those ellipses

    -RED???
    
    jsulmJ 1 Reply Last reply
    0
    • PerdrixP Perdrix

      I ran the following code in the debugger with breakpoint set on the first pen.setColor call.

      if (stars[i].m_bAdded)
      	pen.setColor(qRgba(0, 0, 255, m_bCometMode ? 255 * 0.5 : 255));
      else
      	pen.setColor(qRgba(0, 190, 0, m_bCometMode ? 255 * 0.5 : 255));
      
      painter.drawEllipse(rc);
      

      the breakpoint was never hit.

      Putting the breakpoint on the second pen.setColor was hit many times (for every star).

      So I know that the colour used to draw the ellipse should be green.

      The pixmap is built and then written to the screen in the paintEvent handler:

      	void EditStars::paintEvent([[maybe_unused]] QPaintEvent* event)
      	{
      		QPainter painter(this);
      		drawOnPixmap();
      		//
      		// Draw the stuff we drew onto the working pixmap onto the screen
      		//
      		painter.setBackgroundMode(Qt::TransparentMode);
      		painter.drawPixmap(0, 0, pixmap);
      
      		painter.end();
      	}
      

      So why are all those ellipses

      -RED???
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Perdrix I don't see where you're using the pen actually?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by Perdrix
        #3

        Aaarrrggghhh! painter.setPen(pen) would help wouldn't it! <<BLUSH>>

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