1

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?

Community
  • 1
  • 1
W.K.S
  • 9,787
  • 15
  • 75
  • 122
  • Have you tried a tab? Also, is there anything wrong with two labels? – Karolis Juodelė Jan 16 '12 at 17:23
  • A tab wouldn't suit this purpose. I'm basically displaying properties. I want the property name on the left and the value on the right. There's nothing wrong with two labels, but I was hoping to avoid it since I have around 7 properties I want to list, and I don't want to make twice that many labels. – W.K.S Jan 16 '12 at 17:26
  • 3
    Two separate labels sounds like the right approach, though: One immutable one that contains the field *description*, and one mutable one that contains the field *content*. Doesn't the form editor make this very easy to set up, anyway? – Kerrek SB Jan 16 '12 at 17:30

1 Answers1

3

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);
Dusty Campbell
  • 3,146
  • 31
  • 34