2

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.

adam.baker
  • 1,447
  • 1
  • 14
  • 30

1 Answers1

1
label.setAlignment(Qt::AlignRight);
Iuliu
  • 4,001
  • 19
  • 31