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. How to equally distribute QLabels in QStatusBar

How to equally distribute QLabels in QStatusBar

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.9k 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.
  • M Offline
    M Offline
    milan
    wrote on last edited by
    #1

    Hello, how can I equally distribute (for example three) QLabels in QStatusBar? I tried to add QHBoxLayout. But I cannot add Layout to QStatusBar, as it said it already has layout:

    QWidget::setLayout: Attempting to set QLayout "" on QStatusBar "", which already has a layout
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What about putting that layout on a "container" widget and then put that widget in the QStatusBar ?

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

      M 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        What about putting that layout on a "container" widget and then put that widget in the QStatusBar ?

        M Offline
        M Offline
        milan
        wrote on last edited by
        #3

        @SGaist . Thanks, I already did similar as you suggested.

         statusBar = new QStatusBar();
         QLabel *statuslabel1 = new QLabel;
         QLabel *statuslabel2 = new QLabel;
         QLabel *statuslabel3 = new QLabel;
         statuslabel1->setText("Left");
         statuslabel2->setText("Centre");
         statuslabel3->setText("Right");
         statusLayout = new QHBoxLayout;
         statusLayout->addWidget(statuslabel1);
         statusLayout->addStretch();
         statusLayout->addWidget(statuslabel2);
         statusLayout->addStretch();
         statusLayout->addWidget(statuslabel3);
         QWidget *container = new QWidget;
         container->setLayout(statusLayout);
         statusBar->addWidget(container);
        

        This gave me like this statusBar.
        0_1537946345690_225c22e8-9304-40d7-bdcb-9cda8fa78cdf-image.png .

        This is not what I wanted, I wanted Left label to be at left, Centre to be at centre and Right label at right. Of course, they should retain their position even when the window is resized or at least when the application opens.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          milan
          wrote on last edited by
          #4

          What I dont understand is why the statusBar is only 50% of available width.

          0_1537951833917_c8cce369-7e1f-4bfd-81fa-a5a9ce8f3bb2-image.png

          jsulmJ 1 Reply Last reply
          0
          • M milan

            What I dont understand is why the statusBar is only 50% of available width.

            0_1537951833917_c8cce369-7e1f-4bfd-81fa-a5a9ce8f3bb2-image.png

            jsulmJ Online
            jsulmJ Online
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @milan You should rather do

            statusBar->layout()->addWidget(container);
            

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

            M 1 Reply Last reply
            -1
            • jsulmJ jsulm

              @milan You should rather do

              statusBar->layout()->addWidget(container);
              
              M Offline
              M Offline
              milan
              wrote on last edited by
              #6

              @jsulm . I get like this after the change. I removed widget stylesheets too in meantime.
              0_1537953472135_93ff44de-6302-444d-9a99-0523f2ce00e2-image.png .

              You can see now, container widget is in right.

              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