QGraphicsSimpleTextItem not outlined



  • Hello Qt community.

    The following code fails to outline the text:

    auto ert = myScene->addSimpleText("99", otherFont);
    ert->setBrush(QBrush(Qt::white));
    ert->setPen(QPen(Qt::blue));
    

    I get this: http://i.imgur.com/AfHz8U7.png (As you can see, there's no blue.) Do I need to set up some option, or is outlining allowed by default and this is clearly a bug? Thanks in advance for your help.


  • Moderators

    AFAIK there's no need for any manual setup to get this and it indeed shows correctly to me (with blue outline).
    What Qt version and platform are you on?



  • @Chris-Kawa Qt-5.5 and Ubuntu LTS 14.04. It's very possible that the latter causes the issue, it wouldn't be the first time...


  • Moderators

    I just tested it on a Ubuntu 14.04 VM and it also runs fine.
    Could you check with this snippet?

    #include <QApplication>
    #include <QGraphicsView>
    #include <QGraphicsScene>
    #include <QGraphicsSimpleTextItem>
    
    int main(int argc, char *argv[]) {
        QApplication a(argc, argv);
    
        QGraphicsView w;
        w.setScene(new QGraphicsScene());
        w.setBackgroundBrush(QBrush(Qt::black));
    
        auto item = w.scene()->addSimpleText("99", QFont(QString(), 50));
        item->setBrush(QBrush(Qt::white));
        item->setPen(QPen(Qt::blue));
        w.show();
    
        return a.exec();
    }
    


  • This post is deleted!


  • This post is deleted!


  • @Chris-Kawa I'm just posting to let you know that Ubuntu LTS 14.04 was indeed the problem. Everything works fine on Ubuntu 15.04! Thanks for your help!

    I'm about to switch this thread to "solved", but the result is still a bit weird: picture. Left is what we were talking about, right is the same text without QPen/outline. As you can see, the white pixels have been partially eaten by the outline, and I was wondering if it were possible to fix that. Can we draw the outline completely out of the characters, rather than inside them?



  • I would like to bump this. I've actually tried to make the font bold, and I was hoping to kind of solve the problem this way. But I couldn't, neither on Ubuntu 15.04 nor on Ubuntu 14.04 LTS. The lines

    otherFont.setBold(true);
    otherFont.setWeight(99);
    

    do not seem to work at all (either one). Any ideas?



  • I would like to bump this again... Is there anyone who actually gets an outline out of QPen, rather than an inline?


  • Qt Champions 2016

    @Pippin
    Hi
    maybe try with some other font.
    on windows 7, the outline is really a outline
    http://postimg.org/image/b7bpxabwl/
    Update:
    Also tried Chis code in ubuntu.
    Look 100% the same as in win 7.



  • @mrjj I've tried different fonts and the result is always the same. If the width of the QPen gets thick enough, the entire text is filled with the pen's color.

    Edit: Are you sure you don't have the same problem? The way the blue is drawn around the 9 makes me believe that it is drawn inside the characters too.


  • Qt Champions 2016

    @Pippin
    Ok. must be something on your platform then.
    Works fine here on win 7 and ubuntu 64 bit.
    Its outside the font area.

    Update:
    I can see what you mean when using small fonts.



  • @mrjj Could you try the same code you used but with QPen(Qt::blue, 50) please? The way the blue is drawn in the corner of the number '9' seems to indicate that you actually have the same problem. Not sure how to word this, just tell me if that still works correctly for you.

    If everything works on your computer with Ubuntu, it really should be the same on mine...


  • Qt Champions 2016

    @Pippin
    Well at small size it does overlap
    http://postimg.org/image/ywjidp6pt/
    also if big pen, then it overlaps.
    http://postimg.org/image/wtn3l0m3n/

    So yes, you are right. its really not a true outline.



  • Okay so this isn't just me. Thanks a lot for your help @mrjj. We're supposed to report the bug right?


  • Moderators

    I believe that's how an outline is suppose to work. It outlines the path that forms the letter, not the filling, so if the letter has a filling brush the outline will go both inside and outside of it:
    outline

    The red line is a path that forms the letters.



  • @Chris-Kawa Does this mean that there's no real solution to my problem? I can't outline my text without "eating" it just as much as I outline it?

    Or maybe I could print it twice so that the inline is hidden by the second text ---> Haha I've just tested this and it works. Totally makeshift but it works.


  • Qt Champions 2016

    @Chris-Kawa
    Hi, can I ask how u get it to show the path ?


  • Moderators

    @mrjj I just created two items. The second one with no filling and a cosmetic brush (1px):

    auto item = w.scene()->addSimpleText("ABC99", QFont(QString(), 100));
    item->setBrush(QBrush(Qt::white));
    item->setPen(QPen(Qt::blue, 8));
    
    auto item2 = w.scene()->addSimpleText("ABC99", QFont(QString(), 100));
    item2->setBrush(QBrush(Qt::transparent));
    item2->setPen(QPen(Qt::red, 0));
    

    but that's just to quickly show what I mean. I don't claim it's a good way to do it in general.

    @Pippin I guess that's one way to do it. It's a shame since you pay a doubled cost of stroking the path for each text, but I couldn't find a better way to do it. I thought of using a two-color gradient for the outline, the inside one using the filling color, but there doesn't seem to be an easy way to make the gradient follow the path. Oh well. if it works it works.


  • Qt Champions 2016

    ahh. i see. thank you.
    Was not aware of the cosmetic pen function.


Log in to reply
 

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