Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-12149

setPen after drawRect and before drawText does not draw the text with the right color.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • None
    • 4.6.0
    • GUI: Painting
    • None
    • Windows XP Pro 2002 SP3

    Description

      I wanna draw a rect with a given pen color and a text with the same pen color
      Here is a piece of code I use do do this, in the paint method of my QGraphicsItem

       void myGraphicsItem::paint( QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/ )
      {   
          int alpha = 60;
      
          QColor penColor(83,93,111,alpha);
          painter->setPen(penColor);
          painter->drawRect(myRect);
          
          painter->drawText(myTextPosition, QString( "My Text" ));
      }
      

      The text is drawn in strong black, with no transparency
      Adding the following code before the drawTextprovides the same effect :
      // Provide another pen with the same color
      QColor penColor2(83,93,111,alpha);
      painter->setPen(penColor2);

      Finally providing a new pen with another color has the expected effet :
      // Here, we change only the red component from 83 to 80 for example
      QColor penColor2(80,93,111,alpha);
      painter->setPen(penColor2);

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.graphics.and.multimedia Qt Graphics Team
            nb Nicolas Bonet
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes