Important: Please read the Qt Code of Conduct -

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

  • 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("z-theme-light")==0 ||"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());
        pixmap.fill( Qt::transparent );
        QPainter *painter = new QPainter(&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

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


    and you store the icons in the Qt resource system

Log in to reply