Results 1 to 3 of 3

Thread: Hex Zero

  1. #1
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Hex Zero

    Using QLineEdit::setHtml with font changes requires "#rrggbb" for arbitrary colors. Each QColor can be broken into the requisite subset easily, and then converted to a hex string. However, the string for zero in hex should be "00" yet the following code gives "0". The workaround is obvious but I am curious as to the reason if anyone knows.
    Qt Code:
    1. QString hexZero = QString::number(0, 16);
    To copy to clipboard, switch view to plain text mode 
    Perhaps there is a better way to get the hex string for a given QColor, and I'm just too blind to see it.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    506
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Hex Zero

    Hi, you can use one of the QString::arg() methods. They allow to specify a minimum width of the result.

    Ginsengelf

  3. The following user says thank you to Ginsengelf for this useful post:

    johnmauer (17th June 2010)

  4. #3
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Hex Zero

    Works great. Thanks.

    Qt Code:
    1. QString fontColorSet = "#%1%2%3";
    2. fontColorSet = fontColorSet.arg(QString::number(fontColor.red(), 16), 2,'0')
    3. .arg(QString::number(fontColor.green(), 16) ,2,'0')
    4. .arg(QString::number(fontColor.blue(), 16),2,'0');
    To copy to clipboard, switch view to plain text mode 

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.