qcolor 和 htmlcolor 互转

转自:https://blog.csdn.net/qq_28107929/article/details/105104556#:~:text=RGB%E9%A2%9C%E8%89%B2%20%E7%9A%84%20%E8%BD%AC%20%E6%8D%A2%EF%BC%9A%20%60%60%60cpp%20%23include%20%3CQtGui%3E%20Q,Rgb%20%60%E5%87%BD%E6%95%B0%E6%8E%A5%E5%8F%97%E4%B8%80%E4%B8%AA%2016%E8%BF%9B%E5%88%B6%E9%A2%9C%E8%89%B2%20%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%BD%9C%E4%B8%BA%E5%8F%82%E6%95%B0%EF%BC%8C%E5%B9%B6%E5%B0%86%E5%85%B6%20%E8%BD%AC%20%E6%8D%A2%E4%B8%BAQ%20Color%20%E5%AF%B9%E8%B1%A1%E3%80%82

注意:#f0f0f0

QString  str = "f0f0f0";不要带#

1 QColor c(255,0,255);
2 //QColor >> QRgb(uint)
3 QRgb mRgb = qRgb(c.red(),c.green(),c.blue());
4 //QRgb(uint) >> QColor;
5 QColor mColor = QColor(mRgb);
6 //QRgb(uint) >> QString;
7 QString mRgbStr = QString::number(mRgb,16);
8 //QString >> unint >> QColor
9 QColor color2(mRgbStr.toUInt(NULL,16));

 

posted @ 2023-11-28 15:41  阳光下的小土豆  阅读(115)  评论(0编辑  收藏  举报