コード例 #1
0
QString IGTLinkConversionSonixCXLegacy::extractColorFormat(QString deviceName, QString* cleanedDeviceName)
{
	QString format = "";
	QRegExp colorFormat("\\[[A-Za-z]{1,4}\\]");
	if (colorFormat.indexIn(deviceName) > 0)
	{
		format = colorFormat.cap(0).remove("[").remove("]");
	}

	if (cleanedDeviceName)
	{
		*cleanedDeviceName = deviceName.remove(colorFormat).trimmed();
	}

	return format;
}
コード例 #2
0
ファイル: textedit.cpp プロジェクト: thesoulless/SoulNote
/*!
 *  \fn void TextEdit::highlight(const QString &findString, QTextDocument::FindFlags options)
 *  Highlight texts that match the find query in document.
 *
 *  \param &findString  text to be find in document.
 *  \param options      QTextDocument::FindFlags find options.
 */
void TextEdit::highlight(const QString &findString, QTextDocument::FindFlags options)
{
    clearFind();
    QTextDocument *document = this->document();
    QTextCursor highlightCursor(document);
    QTextCharFormat colorFormat(highlightCursor.charFormat());
    colorFormat.setForeground(Qt::white);
    QPalette a;

    QBrush back(a.brush(QPalette::Link).color());//.darker(120));
    colorFormat.setBackground(back);

    while (!highlightCursor.isNull() && !highlightCursor.atEnd()) {
        highlightCursor = document->find(findString, highlightCursor, options);

        if (!highlightCursor.isNull()) {
            highlightCursor.setCharFormat(colorFormat);
        }
    }
}