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. [SOLVED] Text with outline pen failure
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Text with outline pen failure

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 4.9k Views 1 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.
  • M Offline
    M Offline
    mickyj
    wrote on last edited by
    #1

    I cannot get some simple text to paint with an outline. I wanted red text with a black outline. So I did this:

    @
    Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog)
    {
    ui->setupUi(this);
    scene = new QGraphicsScene(this);
    ui->graphicsView->setScene(scene);

    QBrush redbrush(Qt::red);
    QPen   blackpen(Qt::black);
    blackpen.setWidth(15);
    blackpen.setStyle(Qt::SolidLine);
    
    QFont font;
    font.setFamily("Times New Roman");
    font.setPointSize(200);
    
    txt = new QGraphicsSimpleTextItem();
    txt->setText("Hi");
    txt->setFont(font);
    txt->setPen(blackpen);
    txt->setBrush(redbrush);
    
    scene->addItem(txt);
    }
    

    @

    I get red text as I had wanted, but it does not have a black outline. What else must I do to make this work? If I change the color of the brush, the text will change color appropriately but I cannot get the QPen to paint its border into the scene. Any help would be appreciated. Must I override paint() for this class?

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

      You can try QGraphicsPathItem instead of QGraphicsSimpleTextItem. Create QPainterPath, use addText() on it and setPath() on the item.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mickyj
        wrote on last edited by
        #3

        Krzysztof,

        That works perfectly. Many thanks to you. Now how does on set this to SOLVED?

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

          Great, glad I could help.
          Just use the "edit" link on the right side of the post and edit the title by prepending [SOLVED] to it.

          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