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 setAlignment of QGroupBox

how to setAlignment of QGroupBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
31 Posts 4 Posters 15.8k 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.
  • P Offline
    P Offline
    p3c0
    Moderators
    wrote on 16 Oct 2016, 06:21 last edited by
    #19

    @cerr So now set vbox as a layout to its parent widget.

    157

    C 1 Reply Last reply 18 Oct 2016, 01:54
    0
    • P p3c0
      16 Oct 2016, 06:21

      @cerr So now set vbox as a layout to its parent widget.

      C Offline
      C Offline
      cerr
      wrote on 18 Oct 2016, 01:54 last edited by
      #20

      @p3c0 said in how to setAlignment of QGroupBox:

      @cerr So now set vbox as a layout to its parent widget.

      Did you mean like?

      QVBoxLayout *vbox = new QVBoxLayout;
          vbox->addWidget(terminalWidget);
          vbox->addWidget(groupBox);
          vbox->addWidget(parent);
          groupBox->setLayout(vbox);
          terminalWidget ->show();
      ``` - that doesn't let me open my application...
      1 Reply Last reply
      0
      • P Offline
        P Offline
        p3c0
        Moderators
        wrote on 18 Oct 2016, 05:10 last edited by
        #21

        @cerr Probably something like this. Assuming QDialog is my main widget which contains groupbox.

        QVBoxLayout *mainLayout = new QVBoxLayout;
        myDialog->setLayout(mainLayout);
        
        //Now add widgets into this layout
        
        mainLayout->addWidget(groupBox);// groupbox first
        mainLayout->addWidget(terminalWidget);
        

        Now in your case if you want to add terminalWidget inside a groupbox's layout you can create new one and add into it keeping mainLayout as it is.

        157

        C 1 Reply Last reply 19 Oct 2016, 03:32
        1
        • P p3c0
          18 Oct 2016, 05:10

          @cerr Probably something like this. Assuming QDialog is my main widget which contains groupbox.

          QVBoxLayout *mainLayout = new QVBoxLayout;
          myDialog->setLayout(mainLayout);
          
          //Now add widgets into this layout
          
          mainLayout->addWidget(groupBox);// groupbox first
          mainLayout->addWidget(terminalWidget);
          

          Now in your case if you want to add terminalWidget inside a groupbox's layout you can create new one and add into it keeping mainLayout as it is.

          C Offline
          C Offline
          cerr
          wrote on 19 Oct 2016, 03:32 last edited by cerr
          #22

          @p3c0 said in how to setAlignment of QGroupBox:

          Thanks for pitching in, I guess this is what I was missing. I now have this (which I can work with going forward):

          Terminal* Session::addTerminal(QWidget* parent)
          {    
            
              QGroupBox *groupBox = new QGroupBox(tr("Test"), parent);    
              groupBox->setAlignment(Qt::AlignLeft);
              QVBoxLayout *vbox = new QVBoxLayout;    
              groupBox->setLayout(vbox);    
              vbox->addWidget(groupBox);
              
              Terminal* terminal = new Terminal(parent);
              connect(terminal, SIGNAL(activated(int)), this, SLOT(setActiveTerminal(int)));
              connect(terminal, SIGNAL(manuallyActivated(Terminal*)), this, SIGNAL(terminalManuallyActivated(Terminal*)));
              connect(terminal, SIGNAL(titleChanged(int,QString)), this, SLOT(setTitle(int,QString)));
              connect(terminal, SIGNAL(keyboardInputBlocked(Terminal*)), this, SIGNAL(keyboardInputBlocked(Terminal*)));
              connect(terminal, SIGNAL(silenceDetected(Terminal*)), this, SIGNAL(silenceDetected(Terminal*)));
              connect(terminal, SIGNAL(destroyed(int)), this, SLOT(cleanup(int)));
              m_terminals.insert(terminal->id(), terminal);    
              QWidget* terminalWidget = terminal->terminalWidget();
              
              vbox->addWidget(terminalWidget);
              
              terminalWidget->show();
              if (groupBox) groupBox->setFocus();
              return terminal;
          }
          

          But now back to the top, while it looks like this now: https://postimg.org/image/viahdjbwp/ how do I get the GroupBox label aligned to the left?

          1 Reply Last reply
          0
          • P Offline
            P Offline
            p3c0
            Moderators
            wrote on 19 Oct 2016, 06:08 last edited by p3c0
            #23

            @cerr Here is a small example that demonstrates it:

            int main(int argc, char *argv[])
            {
                QApplication app(argc, argv);
            
                QDialog d;
                d.resize(400, 400);
                d.show();
            
                QVBoxLayout mainLayout;
                d.setLayout(&mainLayout);
            
                QGroupBox box;
                box.setTitle("MyGroupBox");
                mainLayout.addWidget(&box);
            
                QLabel label("MyLabel");
                mainLayout.addWidget(&label);
              
                return app.exec();
            }
            

            You can see the QGroupBox properly aligned to the left. Here the Groupbox is added into the main widget's layout. Try to do in the similar way.

            157

            C 1 Reply Last reply 20 Oct 2016, 12:42
            1
            • P p3c0
              19 Oct 2016, 06:08

              @cerr Here is a small example that demonstrates it:

              int main(int argc, char *argv[])
              {
                  QApplication app(argc, argv);
              
                  QDialog d;
                  d.resize(400, 400);
                  d.show();
              
                  QVBoxLayout mainLayout;
                  d.setLayout(&mainLayout);
              
                  QGroupBox box;
                  box.setTitle("MyGroupBox");
                  mainLayout.addWidget(&box);
              
                  QLabel label("MyLabel");
                  mainLayout.addWidget(&label);
                
                  return app.exec();
              }
              

              You can see the QGroupBox properly aligned to the left. Here the Groupbox is added into the main widget's layout. Try to do in the similar way.

              C Offline
              C Offline
              cerr
              wrote on 20 Oct 2016, 12:42 last edited by
              #24

              @p3c0 said in how to setAlignment of QGroupBox:

              Thanks but I want the
              box.setTitle("MyGroupBox"); title to be left aligned, so I altered your example code to:

                  QGroupBox box;
                  box.setTitle("MyGroupBox");
                  box.setAlignment(Qt::AlignLeft);
                  mainLayout.addWidget(&box);
              

              but like in my application above, the title stays centered, can it be left aligned at all?
              This is from http://doc.qt.io/qt-5/qgroupbox.html#alignment-prop:

              alignment : Qt::Alignment

              This property holds the alignment of the group box title.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 20 Oct 2016, 21:12 last edited by
                #25

                Hi,

                Which window manager are you using ?

                I just tested on macOS and the alignment is working properly (self built 5.7)

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

                C 1 Reply Last reply 21 Oct 2016, 04:01
                0
                • S SGaist
                  20 Oct 2016, 21:12

                  Hi,

                  Which window manager are you using ?

                  I just tested on macOS and the alignment is working properly (self built 5.7)

                  C Offline
                  C Offline
                  cerr
                  wrote on 21 Oct 2016, 04:01 last edited by
                  #26

                  @SGaist said in how to setAlignment of QGroupBox:

                  Hi,

                  Which window manager are you using ?

                  I just tested on macOS and the alignment is working properly (self built 5.7)

                  KDE 5.5.5 with Qt 5.5.1 (Kubuntu 16.04)

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    p3c0
                    Moderators
                    wrote on 21 Oct 2016, 05:18 last edited by
                    #27

                    @cerr What does QApplication::style() returns in your case ?

                    157

                    C 1 Reply Last reply 22 Oct 2016, 03:42
                    0
                    • P p3c0
                      21 Oct 2016, 05:18

                      @cerr What does QApplication::style() returns in your case ?

                      C Offline
                      C Offline
                      cerr
                      wrote on 22 Oct 2016, 03:42 last edited by
                      #28

                      @p3c0 said in how to setAlignment of QGroupBox:

                      @cerr What does QApplication::style() returns in your case ?

                      ? std::cout << "style:" << QApplication::style() << std::endl; returns:style:0x12a4590 is this what you were looking for?

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        p3c0
                        Moderators
                        wrote on 22 Oct 2016, 05:29 last edited by
                        #29

                        @cerr I was just trying to find out what style was you application using. I assumed you might use qDebug() which would have properly printed the object info. Anyway try this:

                        QApplication::style()->objectName();
                        

                        If it prints "fusion" (atleast on my system it does, KDE too here) then the the problem might be related to this bug which says it was fixed in Qt 5.6.1. Can you try the newer version ?

                        157

                        C 1 Reply Last reply 22 Oct 2016, 05:38
                        0
                        • P p3c0
                          22 Oct 2016, 05:29

                          @cerr I was just trying to find out what style was you application using. I assumed you might use qDebug() which would have properly printed the object info. Anyway try this:

                          QApplication::style()->objectName();
                          

                          If it prints "fusion" (atleast on my system it does, KDE too here) then the the problem might be related to this bug which says it was fixed in Qt 5.6.1. Can you try the newer version ?

                          C Offline
                          C Offline
                          cerr
                          wrote on 22 Oct 2016, 05:38 last edited by
                          #30

                          @p3c0 said in how to setAlignment of QGroupBox:

                          objectName();

                          Alright yes, qDebug() << "style:" << QApplication::style()->objectName(); gives me style: "breeze"

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            p3c0
                            Moderators
                            wrote on 22 Oct 2016, 05:42 last edited by
                            #31

                            @cerr I can only suggest you to try with latest Qt version to rule out the possibility of this bug.

                            157

                            1 Reply Last reply
                            0

                            28/31

                            22 Oct 2016, 03:42

                            • Login

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