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. Basic question, labels in vertical layout not showing...
Forum Updated to NodeBB v4.3 + New Features

Basic question, labels in vertical layout not showing...

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 666 Views 2 Watching
  • 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    Sorry if this is one of those basic questions. I have a window on the display, I want to add quick debug information to the form. I have added a label which was simple enough:

    mplblAddress = new QLabel(this);
    mplblAddress->setText(cstrAddress);
    

    The above works, now I want two lines so I thought, add a QVBoxLayout then add both labels to the layout:

    QVBoxLayout* pobjVBLO(new QVBoxLayout(this));
    mplblAddress = new QLabel;
    mplblAddress->setText(csrAddress);
    pobjVBLO->addWidget(mplblAddress);
    mplblInfo = new QLabel;
    mplblInfo->setText(cstrInfo);
    pobjVBLO->addWidget(mplblInfo);
    

    Nothing is displayed, I also tried:

    QVBoxLayout* pobjVBLO(new QVBoxLayout;
    mplblAddress = new QLabel;
    mplblAddress->setText(csrAddress);
    pobjVBLO->addWidget(mplblAddress);
    mplblInfo = new QLabel;
    mplblInfo->setText(cstrInfo);
    pobjVBLO->addWidget(mplblInfo);
    setLayout(pobjVBLO);
    

    Nothing is displayed this way either. What haven't I done?

    this is the window class.

    Kind Regards,
    Sy

    jsulmJ 1 Reply Last reply
    0
    • SGaistS SGaist

      And here we have a winner: QMainWindow. That class already has a layout that does all the docking, toolbar, etc handling and that cannot be replaced.

      SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #7

      @SGaist , ok, fixed by adding the following:

      QWidget* pobjWidget(new QWidget(this));
      QVBoxLayout* pobjVBLO(new QVBoxLayout);
      pobjVBLO->addWidget(mplblAddress);
      pobjVBLO->addWidget(mplblInfo);
      pobjWidget->setLayout(pobjVBLO);
      setCentralWidget(pobjWidget);
      

      Kind Regards,
      Sy

      1 Reply Last reply
      0
      • SPlattenS SPlatten

        Sorry if this is one of those basic questions. I have a window on the display, I want to add quick debug information to the form. I have added a label which was simple enough:

        mplblAddress = new QLabel(this);
        mplblAddress->setText(cstrAddress);
        

        The above works, now I want two lines so I thought, add a QVBoxLayout then add both labels to the layout:

        QVBoxLayout* pobjVBLO(new QVBoxLayout(this));
        mplblAddress = new QLabel;
        mplblAddress->setText(csrAddress);
        pobjVBLO->addWidget(mplblAddress);
        mplblInfo = new QLabel;
        mplblInfo->setText(cstrInfo);
        pobjVBLO->addWidget(mplblInfo);
        

        Nothing is displayed, I also tried:

        QVBoxLayout* pobjVBLO(new QVBoxLayout;
        mplblAddress = new QLabel;
        mplblAddress->setText(csrAddress);
        pobjVBLO->addWidget(mplblAddress);
        mplblInfo = new QLabel;
        mplblInfo->setText(cstrInfo);
        pobjVBLO->addWidget(mplblInfo);
        setLayout(pobjVBLO);
        

        Nothing is displayed this way either. What haven't I done?

        this is the window class.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @SPlatten Where are you adding the labels to the layout?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        SPlattenS 1 Reply Last reply
        0
        • jsulmJ jsulm

          @SPlatten Where are you adding the labels to the layout?

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #3

          @jsulm , sorry, I was typing the source in on a different computer to post as the system the code is on does not have internet access, I missed out those lines, I've edited my original correcting the post.

          Kind Regards,
          Sy

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

            Hi,

            Any chances that you already have a layout on that widget ?

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

            SPlattenS 1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              Any chances that you already have a layout on that widget ?

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by SPlatten
              #5

              @SGaist , I don't think so because there is no UI and the class is derived from QMainWindow, the constructor has nothing in it....however I will call layout to see what is returned.

              [Edit], so I added:

              QLayout* pobjLayout(this->layout());
              

              And an address is returned NOT null, so where or what would be setting this?

              Kind Regards,
              Sy

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

                And here we have a winner: QMainWindow. That class already has a layout that does all the docking, toolbar, etc handling and that cannot be replaced.

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

                SPlattenS 1 Reply Last reply
                2
                • SGaistS SGaist

                  And here we have a winner: QMainWindow. That class already has a layout that does all the docking, toolbar, etc handling and that cannot be replaced.

                  SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #7

                  @SGaist , ok, fixed by adding the following:

                  QWidget* pobjWidget(new QWidget(this));
                  QVBoxLayout* pobjVBLO(new QVBoxLayout);
                  pobjVBLO->addWidget(mplblAddress);
                  pobjVBLO->addWidget(mplblInfo);
                  pobjWidget->setLayout(pobjVBLO);
                  setCentralWidget(pobjWidget);
                  

                  Kind Regards,
                  Sy

                  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