Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsSimpleTextItem not outlined

QGraphicsSimpleTextItem not outlined

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 3 Posters 6.9k Views 3 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.
  • P Offline
    P Offline
    Pippin
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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?

      P 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        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?

        P Offline
        P Offline
        Pippin
        wrote on last edited by Pippin
        #3

        @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...

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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();
          }
          
          1 Reply Last reply
          1
          • P Offline
            P Offline
            Pippin
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • P Offline
              P Offline
              Pippin
              wrote on last edited by Pippin
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • P Offline
                P Offline
                Pippin
                wrote on last edited by Pippin
                #7

                @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?

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  Pippin
                  wrote on last edited by Pippin
                  #8

                  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?

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Pippin
                    wrote on last edited by
                    #9

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

                    mrjjM 1 Reply Last reply
                    0
                    • P Pippin

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

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #10

                      @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.

                      1 Reply Last reply
                      1
                      • P Offline
                        P Offline
                        Pippin
                        wrote on last edited by Pippin
                        #11

                        @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.

                        mrjjM 1 Reply Last reply
                        0
                        • P Pippin

                          @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.

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by mrjj
                          #12

                          @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.

                          1 Reply Last reply
                          1
                          • P Offline
                            P Offline
                            Pippin
                            wrote on last edited by Pippin
                            #13

                            @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...

                            mrjjM 1 Reply Last reply
                            0
                            • P Pippin

                              @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...

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @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.

                              1 Reply Last reply
                              1
                              • P Offline
                                P Offline
                                Pippin
                                wrote on last edited by Pippin
                                #15

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

                                1 Reply Last reply
                                0
                                • Chris KawaC Offline
                                  Chris KawaC Offline
                                  Chris Kawa
                                  Lifetime Qt Champion
                                  wrote on last edited by Chris Kawa
                                  #16

                                  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.

                                  P mrjjM 2 Replies Last reply
                                  2
                                  • Chris KawaC Chris Kawa

                                    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.

                                    P Offline
                                    P Offline
                                    Pippin
                                    wrote on last edited by Pippin
                                    #17

                                    @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.

                                    1 Reply Last reply
                                    0
                                    • Chris KawaC Chris Kawa

                                      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.

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

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

                                      1 Reply Last reply
                                      0
                                      • Chris KawaC Offline
                                        Chris KawaC Offline
                                        Chris Kawa
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #19

                                        @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.

                                        1 Reply Last reply
                                        1
                                        • mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #20

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

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