PDA

View Full Version : Text Alignment in QMainWindow Widget



GTBuilder
31st January 2012, 21:18
I'm designing a MainWindow application that contains a single menu item which I wanted to appear on the RHS of the menuBar. To accomplish this, I set the layoutDirection to RightToLeft.

However, this had some unusual consequences:

One of my pushButtons had the text, 'Do the operation?' which appeared as, '?Do the operation' I had to re-write as, '?Do the operation' to have it appear correctly.

All the QLineEdits had their text right justified. To get left justify, I had to insert a lineEdit->setAlignment( Qt::AlignRight).
All the QTextEdits appeared correctly left justified.

Should I expect the layoutDirection of the parent to impact some of the children?

I'm using version 4.4.3. O/S is WindowsXP and 7.

ChrisW67
1st February 2012, 05:22
Prior to Qt 4.7 setting the QWidget::layoutDirection() also set the text direction. English is left-to-right but is being treated as if it is right to left. I am not sure if switching to 4.8 will achieve what you want.

Do you really want to design a non-standard menu bar anyway?

GTBuilder
9th February 2012, 12:30
My naive approach was to change the layout direction of the entire QMainWindow widget which resulted in several problems. I now realize that individual components of QMainWindow can be modified. The following in either the constructor or in the createMenu() module accomplishes the desired layout:

menuBar()->setLayoutDirection( Qt::RightToLeft);