Set text direction for QLabel?

依然范特西╮ 提交于 2019-12-11 02:45:07

问题


Is there a way to set the text direction for a QLabel? I've got a situation in which I have QLabel objects whose text is only punctuation, and I want that to be displayed either in RTL or LTR format. (For instance, parentheses or quotation marks need to reverse depending on the text direction.) I've tried calling QLabel::setLayoutDirection, but to no effect.

#include <QApplication>
#include <QLabel>

int main(int argc, char **argv)
{
    QApplication app (argc, argv);
    QLabel label(" :  «");
    label.setFont( QFont("Times New Roman", 72) );
    label.setLayoutDirection( Qt::RightToLeft );
    // label.setLayoutDirection( Qt::LeftToRight );
    label.show();
    return app.exec();
}

A workaround at this point is to prepend 0x202E ("Right-to-Left Override") to the string, but that's obviously a bit clunky.


回答1:


label.setAlignment(Qt::AlignRight);


来源:https://stackoverflow.com/questions/26378900/set-text-direction-for-qlabel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!