I have a string. For example:
QString myString = "Today is Tuesday";
The requirement is: when user types a string, if that string is contained in myString
, then that part in the myString
should be bold, and case insensitive (Qt::CaseInsensitive
), but the format of myString
should remain (upper case characters should be upper case and lower case characters should be lower case).
For example:
- user types:
tu
-> Today is Tuesday - user types:
ES
-> Today is Tuesday - user types:
aY
-> Today is Tuesday
This is my function:
void myClass::setBoldForMatching( const QString &p_text )
{
QRegExp regExp( p_text, Qt::CaseInsensitive, QRegExp::RegExp );
if ( !p_text.isEmpty() )
{
if ( myString.contains( regExp ) )
{
myString = myString.replace( p_text, QString( "<b>" + p_text + "</b>" ), Qt::CaseInsensitive );
}
}
}
This function is wrong because
user types t
-> today is tuesday.
What I need is Today is Tuesday
How should I update my function?