How can I align some of the text on the left, and some of it on the right without using two labels
-
16-04-2021 - |
Question
I want to use QLabel
s to display some data in this format
username:.....Erich Lancaster (without dots)
Location:.......Wherever
Is there a way to do this?
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