How can I align some of the text on the left, and some of it on the right without using two labels

StackOverflow https://stackoverflow.com/questions/8884808

  •  16-04-2021
  •  | 
  •  

Question

I want to use QLabels to display some data in this format

username:.....Erich Lancaster (without dots)

Location:.......Wherever

Is there a way to do this?

Was it helpful?

Solution

Seems like using the QFormLayout would be the easiest. Something like:

QFormLayout *formLayout = new QFormLayout;
QLabel *usernameLabel = new QLabel("Erich Lancaster");
usernameLabel->setAlignment(Qt::AlignRight);
formLayout->addRow("username:", usernameLabel);

QLabel *locationLabel = new QLabel("Wherever");
locationLabel->setAlignment(Qt::AlignRight);
formLayout->addRow("Location:", locationLabel);
setLayout(formLayout);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top