Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Align QLabels and QtableWidgets
Forum Update on Monday, May 27th 2025

Align QLabels and QtableWidgets

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Ninawe
    wrote on last edited by
    #1

    Hello,
    I am quite new to Qt and have a few questions.
    My main goal is to create an application, that gets data from a device, to be specific it gets 4 numbers.
    I want them to be displayed like this
    length ___
    height ___
    width ___
    weight ___
    so the data would go on the blanks, and also the units behind the data.
    My first approach was to create a lot of Qlabels that display the data on a Qframe and the units, but I can't get them to be in line, when I create them by hand. So first question: can I get labels aligned? But only the labels I choose, not everything, including the buttons?
    My next approach was a QTableWidget, but when I create one in the designer and put it in the middle of the Qframe, I can't connect to it, like tell it to have 3 columns. Only when I create one in my code it does what it should, but it is always locked in the corner of my window.
    How can I get the QtableWidget in the center of my Qframe and fill it with data?

    Thanks a lot for your help or any ideas as to how to implement this application!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      From your description it looks like you didn't set any layout manager, did you ?

      You might be interested by the QFormLayout for your QLabel related stuff.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Ninawe
        wrote on last edited by
        #3

        No, like I said I am completely new to QT. I only did some tutorial. But I have a layout, that is given and I need to put my Output onto this given QFrame

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Ninawe
          wrote on last edited by
          #4

          I managed to include a QFormLayout and add 4 Rows in the Designer with QLabels as buddies. But how do I change the text the labels will display? i just don't find any good examples
          Thanks!

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Binary91
            wrote on last edited by
            #5

            QLabels have, as many other Qt stuff too, a setText(const QString &) function. So you can change the label's displayed text via
            @QLabel::setText("some text");@

            Btw.: You can pass a text to display directly to QLabel's constructor:
            @QLabel* label = new QLabel("some text");@

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Look at the Property Editor

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • N Offline
                N Offline
                Ninawe
                wrote on last edited by
                #7

                Ok, I managed to use QLineEdit, because it has the setText Function. I didn't manage however to add a row, that has a QLabel as buddy. That somehow didn't come up in the choices when I click add a row in the Designer.
                But now I have another question: Can I make QLineEdit non editable? So it just displays text and I can't write in it?

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  Binary91
                  wrote on last edited by
                  #8

                  You realized that QLabel also has this functionallity?
                  It's really dirty to abuse QLineEdits just to display text, you have other Qt classes for that.

                  But if you adhere to that, the following should do it for you:
                  @QLineEdit* edit = new QLineEdit("TextToDisplay");
                  edit->setReadOnly(true);@

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    Ninawe
                    wrote on last edited by
                    #9

                    I think I'd rather won't use the Qt Designer. I think it's easier to only code and not mix both. That only confuses me! But thank you for your help!

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved