Setting the text of QLabel to the color of a Pixmap



  • Hi everyone,

    I have been struggling to set the text of my QLabel to the color and texture of a Pixmap. I want the text in the label to have a gold color with a shiny tinge. So I loaded a Pixmap image into the resources and created a Painter event on the QLabel. In the paint event I entered the following code:

    @
    void labelPaint::paintEvent(QPaintEvent *)
    {
    QBrush brush;

    QPixmap Pixmap(":/gold.jpg");
    
    brush.setTexture(Pixmap);
    
    brush.setPixmap(Pixmap);
    
    QPainter painter(this);
    
    painter.setFont(QFont("Times New Roman", 30));
    
    painter.setBrush(brush);
    
    QString myString("some string");
    
    painter.drawText(510,40,myString);
    

    }@

    And I still get the same plain black color as my text. Note that I used both setTexture and setPixmap in my atttempt.
    Thank in advance


  • Moderators

    For drawing lines, outlines and text QPainter uses a pen. Brush is for filling shapes and paths. So instead of changing the brush of the painter change the brush of the pen of the painter (yeah, I know :) ).

    @
    QBrush brush;
    ...//setup brush
    painter.setPen(QPen(brush, 1.0));
    @



  • Great, thank you it worked!


Log in to reply
 

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