[solved] QLabel: Text with shadow?



  • Hi

    I found this example: "Text with shadow":http://www.codeprogress.com/cpp/libraries/qt/showQtExample.php?index=205&key=QLabelShadowedText and tried it out for own use. But as i have expected, the result was not as shown in the output picture. After several minutes with Google i found more examples like this ("e.g":http://qt-project.org/wiki/Text_shadows_in_QLabel_snippests).
    Is this a outdated behaviour of QGraphicsDropShadowEffect on QLabel?
    And how can i actually generate text with some shadow in a QLabel?

    Best,
    Raina


  • Moderators

    Hi,

    Another way would be to subclass the QLabel and override the paintEvent().
    Then in it first draw your text translated to a point using drawText(). Imagine this as a shadow below the actual text.
    eg.
    @
    painter.setPen(Qt::black);
    painter.drawText(rect().translated(3,3),Qt::AlignCenter,"Sample Text");
    //Adjust the coordinates in translated() as per your requirement.
    @

    And then draw the actual text over it as,
    @
    painter.setPen(Qt::red);
    painter.drawText(rect(),Qt::AlignCenter,"Sample Text");
    @

    You can set the the pen width and color as needed.



  • [quote author="p3c0" date="1380956837"]Hi,

    Another way would be to subclass the QLabel and override the paintEvent().
    Then in it first draw your text translated to a point using drawText(). Imagine this as a shadow below the actual text.
    eg.
    @
    painter.setPen(Qt::black);
    painter.drawText(rect().translated(3,3),Qt::AlignCenter,"Sample Text");
    //Adjust the coordinates in translated() as per your requirement.
    @

    And then draw the actual text over it as,
    @
    painter.setPen(Qt::red);
    painter.drawText(rect(),Qt::AlignCenter,"Sample Text");
    @

    You can set the the pen width and color as needed.
    [/quote]

    Hi,

    thanks for your advise.
    It's the more complicated way, and i've already thought about this.
    It's low-priority at the moment, but if i find time i will try it out.

    Best


Log in to reply
 

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