W.K.S
W.K.S

Reputation: 10095

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

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?

Upvotes: 1

Views: 1274

Answers (1)

Dusty Campbell
Dusty Campbell

Reputation: 3156

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);

Upvotes: 3

Related Questions