Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.8.0, 4.8.4, 5.0.0, 5.0.1, 5.2.0
-
None
-
Qt: 4.8.0
Linux pc 3.2.0-2-ARCH #1 SMP PREEMPT Sat Jan 7 14:27:58 CET 2012 x86_64 AMD Phenom(tm) II X4 945 Processor AuthenticAMD GNU/Linux
Description
Everything is ok for latin strings or any strings without mnemonics, but the results are completely wrong on non-latin strings with mnemonics.
The code describes this better.
This code first measures the size of the string, and then calls elidedText with the resulting size.
This should elide the string to its own length, and do not change the string.
QFontMetrics fm = fontMetrics();
QString input = QString::fromWCharArray(L"&Пример");
for (int i=1; i<=input.size()-1; i++) {
QString str = input.left(i+1);
qDebug() << str << fm.elidedText(str, Qt::ElideRight, fm.size(Qt::TextShowMnemonic, str).width(), Qt::TextShowMnemonic);
}
The result is.
"&П" ""
"&Пр" "..."
"&При" "&..."
"&Прим" "&П..."
"&Приме" "&Пр..."
"&Пример" "&При..."
elidedText does not respect & symbol and can give «&...» in output for any string with «&» symbol in it (for certain size argument). This results in underlined «...» shown.
See also:
QString s00 = QString::fromWCharArray(L"Список воспроизведения");
QString s01 = QString::fromWCharArray(L"Список во&спроизведения");
QString s10 = QString::fromWCharArray(L"Источники музыки");
QString s11 = QString::fromWCharArray(L"Ис&точники музыки");
QString s20 = QString::fromWCharArray(L"Some example");
QString s21 = QString::fromWCharArray(L"Some ex&le");
const QFontMetrics fm = fontMetrics();qDebug() << fm.elidedText(s00, Qt::ElideRight, fm.size(Qt::TextShowMnemonic, s00).width(), Qt::TextShowMnemonic);
qDebug() << fm.elidedText(s01, Qt::ElideRight, fm.size(Qt::TextShowMnemonic, s01).width(), Qt::TextShowMnemonic);qDebug() << fm.elidedText(s10, Qt::ElideRight, fm.size(Qt::TextShowMnemonic, s10).width(), Qt::TextShowMnemonic);
qDebug() << fm.elidedText(s11, Qt::ElideRight, fm.size(Qt::TextShowMnemonic, s11).width(), Qt::TextShowMnemonic);qDebug() << fm.elidedText(s20, Qt::ElideRight, fm.size(Qt::TextShowMnemonic, s20).width(), Qt::TextShowMnemonic);
qDebug() << fm.elidedText(s21, Qt::ElideRight, fm.size(Qt::TextShowMnemonic, s21).width(), Qt::TextShowMnemonic);
Results:
"Список воспроизведения"
"Список во&спроизвед..."
"Источники музыки"
"Ис&точники му..."
"Some example"
"Some ex&le"
The output string is wrong with any size parameter given, not only the one returned by QFontMetrics::size().
I do not give another examples (with size given as numbers), becase the fonts may vary with different systems.
The output string may contain invalid substrings (there should be no «&...» in any situation).
This is the cause behind KDE bug https://bugs.kde.org/show_bug.cgi?id=258442 (closed as UPSTEAM).
If you want some *.ui examples or screenshots of the wrong behaviour, see there.