1
我想从纯文本中获取文本颜色。我可以用charFormat()获得fontWeight和其他格式,但是当我调试前景色时,它被设置为无色!如果您使用的Qt4如何从qplaintextedit获取文本颜色?
QTextCursor c = textCursor();
QTextCharFormat result = c.charFormat();
if (result.fontWeight() == QFont::Bold)
qDebug() << "bold text"; //worked
else if (result.fontWeight() == QFont::Normal)
qDebug() << "normal text"; //worked
if (result.foreground().color() == Qt::green)
qDebug() << "green"; //not worked !!
else if (result.foreground().color() == Qt::blue)
qDebug() << "blue"; //not worked !!
else
qDebug() << "no color !!";
TNX
如果您尝试打印'foregroud()。color()',您会得到什么? – alestanis
总是我得到QColor(ARGB 1,0,0,0)... – mgh
这代表白色。你应该在你设置*前景色的地方发布代码。 – alestanis