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
  •  | 
  •  

質問

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?

役に立ちましたか?

解決

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);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top