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. How to get clean text/icon from QTextDocument/html?
Forum Updated to NodeBB v4.3 + New Features

How to get clean text/icon from QTextDocument/html?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 562 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.
  • W Offline
    W Offline
    wesblake
    wrote on last edited by
    #1

    Hello all. I have used the following code to create dialer buttons so that they have the smaller letters underneath like any phone dialer:

    QString numberStyle = "color: #7f7f7f; font-family: Verdana; font-weight: bold;";
        QString numberSize = "font-size: 19px;";
        if(currentTheme.compare("z-theme-light")==0 || currentTheme.compare("z-theme-dark")==0){
                numberStyle = "color: rgba(91, 91, 93, 0.6); font-family: \"SF Pro Text\";";
                numberSize = "font-size: 22px;";
        }
        //Main Page - Dialer Buttons
        QTextDocument doc;
        doc.setHtml("<p align=center style='"+numberStyle+"'><font style='"+numberSize+"'>1</font><br/><font style='font-size: 9px;'> </font></p>");
        QPixmap pixmap(40, doc.size().height());
        doc.setTextWidth(40);
        pixmap.fill( Qt::transparent );
        QPainter *painter = new QPainter(&pixmap);
        painter->setRenderHint(QPainter::Antialiasing);
        painter->setRenderHint(QPainter::TextAntialiasing);
        doc.drawContents(painter);
        ui->dialerOne->setIconSize(pixmap.size());
        ui->dialerOne->setIcon(pixmap);
    

    The problem is, I've tried the renderhints and some other things and it just doesn't come out clean. I'm attaching an image of the output. The final row (*, 0, #) is clean because that's just text directly in the button (since there's nothing underneath it) so the above code doesn't apply to those buttons. As you can see, the first 9 buttons though are not very pretty. Is there something I'm missing to get clean output? Thanks.
    alt text

    Pablo J. RoginaP 1 Reply Last reply
    0
    • W wesblake

      Hello all. I have used the following code to create dialer buttons so that they have the smaller letters underneath like any phone dialer:

      QString numberStyle = "color: #7f7f7f; font-family: Verdana; font-weight: bold;";
          QString numberSize = "font-size: 19px;";
          if(currentTheme.compare("z-theme-light")==0 || currentTheme.compare("z-theme-dark")==0){
                  numberStyle = "color: rgba(91, 91, 93, 0.6); font-family: \"SF Pro Text\";";
                  numberSize = "font-size: 22px;";
          }
          //Main Page - Dialer Buttons
          QTextDocument doc;
          doc.setHtml("<p align=center style='"+numberStyle+"'><font style='"+numberSize+"'>1</font><br/><font style='font-size: 9px;'> </font></p>");
          QPixmap pixmap(40, doc.size().height());
          doc.setTextWidth(40);
          pixmap.fill( Qt::transparent );
          QPainter *painter = new QPainter(&pixmap);
          painter->setRenderHint(QPainter::Antialiasing);
          painter->setRenderHint(QPainter::TextAntialiasing);
          doc.drawContents(painter);
          ui->dialerOne->setIconSize(pixmap.size());
          ui->dialerOne->setIcon(pixmap);
      

      The problem is, I've tried the renderhints and some other things and it just doesn't come out clean. I'm attaching an image of the output. The final row (*, 0, #) is clean because that's just text directly in the button (since there's nothing underneath it) so the above code doesn't apply to those buttons. As you can see, the first 9 buttons though are not very pretty. Is there something I'm missing to get clean output? Thanks.
      alt text

      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #2

      @wesblake what if you try using icons directly instead of constructing every button?

      ui->dialerOne->setIcon("/path/to/icon/one);
      ui->dialerTwo->setIcon("/path/to/icon/two);
      

      and you store the icons in the Qt resource system

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      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