For anyone interested, I reached a solution, described below (took half a day to figure out *sigh*, but then I'm new to this).
I installed a custom delegate on the combo box that would render the strings of LTR languages LTR, and the strings of RTL languages RTL.
To do this, rather than just setting the path of the translation as the item data, I set a custom structure containing the path and a boolean value (since I'd loaded the translation to add it to the combo box, I didn't want to load it every time the delegate painted to figure out which direction the translation was).
This structure of course had to be registered with QMetaType using Q_REGISTER_METATYPE, so that it would work with QVariant.
Finally, the delegate was a subclass of QStyledItemDelegate, with the contents of its paint() method as follows:
initStyleOption(&directionOption, index);
directionOption = option;
InterfaceTranslationInfo info = qvariant_cast<InterfaceTranslationInfo> (index.data(Qt::UserRole));
if (info.rtl) {
directionOption.direction = Qt::RightToLeft;
} else {
directionOption.direction = Qt::LeftToRight;
}
QStyledItemDelegate::paint(painter, directionOption, index);
initStyleOption(&directionOption, index);
directionOption = option;
InterfaceTranslationInfo info = qvariant_cast<InterfaceTranslationInfo> (index.data(Qt::UserRole));
if (info.rtl) {
directionOption.direction = Qt::RightToLeft;
} else {
directionOption.direction = Qt::LeftToRight;
}
QStyledItemDelegate::paint(painter, directionOption, index);
To copy to clipboard, switch view to plain text mode
Seems easy, but met a lot of dead-ends on the way. If anyone could point me to better ways of doing this, it would still be much appreciated, but perhaps this can be of use to someone.
Bookmarks