PDA

View Full Version : RTL QPushButton displays undesired alignment of text and icon



seekeroftruth
11th June 2012, 18:10
Hi,

I am using QPushButton with an icon and text, and the desire is for them to be left-aligned as shown in the first screenshot. My application is translatable to Arabic and therefore I have RTL support. When reversing the layout of the button to RTL, I would like it to just be a mirror image; because my stylesheet says to align left and the button layout is set to RTL, Qt automatically should align everything to the right. However, I get the unexpected results as shown in the second screenshot. This code example is pretty bare bones but I've attached main.cpp and the ui file for reference. Here is the important section of code from the cpp:



#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);

ui->pushButton->setText("TheImage");
ui->pushButton->setIcon(QIcon(":/TheImage"));
ui->pushButton->setStyleSheet("text-align: left");
ui->pushButton->setLayoutDirection(Qt::RightToLeft);
}

MainWindow::~MainWindow()
{
delete ui;
}


Appreciate any suggestions!