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. Insert a character with predefinite settings
Forum Updated to NodeBB v4.3 + New Features

Insert a character with predefinite settings

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 163 Views 2 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
    Martinuccia_96
    wrote on last edited by
    #1

    Hi, everyone:
    I would like to insert into a textEdit block a character with some predefinite characteristics, like the family font, the size, the color. I've used the following solution:

    QFont fnt;
    QTextCharFormat chF;
    QTextCursor c= ui->textEdit->textCursor();
    QColor color2= QColor(0, 0, 255, 127);
    ui->textEdit->setTextColor(color2);
    fnt.setFamily("Comic Sans MS");
    fnt.setBold(true);
    fnt.setItalic(true);
    fnt.setUnderline(true);
    fnt.setPointSizeF(12);
    chF.setFont(fnt);
    c.insertText("X",chF);
    

    but it doesn't insert the character X with the color that i've chosen.
    Can you suggest me another solution, please?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What version of Qt ?
      In what platform ?
      Can you show what you get ?
      Can you provide a minimal compilable example that shows that behavior ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        Hi
        Use
        https://doc.qt.io/qt-5/qtextformat.html#setForeground
        instead of
        ui->textEdit->setTextColor(color2);
        then
        chF.setForeground(color2);

        alt text

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved