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
Forum Updated to NodeBB v4.3 + New Features

how to setAlignment of QGroupBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
31 Posts 4 Posters 15.8k Views 3 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.
  • C Offline
    C Offline
    cerr
    wrote on 15 Oct 2016, 04:23 last edited by
    #1

    want to set the alignment of a QGroupBox title to the left but it stays centered. What I've tried is:

    QGroupBox *groupBox = new QGroupBox(tr("Test"), parent);
    groupBox->setAlignment(Qt::AlignLeft);
    

    any idea how I can get this aligned accordingly? I do not set any particular styles!

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Ratzz
      wrote on 15 Oct 2016, 04:58 last edited by
      #2

      @cerr
      can you show me what u get using image ?

      --Alles ist gut.

      C 1 Reply Last reply 15 Oct 2016, 05:24
      1
      • P Offline
        P Offline
        p3c0
        Moderators
        wrote on 15 Oct 2016, 05:02 last edited by
        #3

        @cerr The default alignment is already Qt::AlignLeft.
        http://doc.qt.io/qt-5/qgroupbox.html#alignment-prop

        157

        1 Reply Last reply
        1
        • R Ratzz
          15 Oct 2016, 04:58

          @cerr
          can you show me what u get using image ?

          C Offline
          C Offline
          cerr
          wrote on 15 Oct 2016, 05:24 last edited by
          #4

          @Ratzz said in how to setAlignment of QGroupBox:

          @cerr
          can you show me what u get using image ?

          https://postimg.org/image/dc7rd4ub9/

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

            @cerr Looks like you have added the groupbox in a layout?
            Can you post the relevant code ?

            157

            C 1 Reply Last reply 15 Oct 2016, 20:16
            1
            • P p3c0
              15 Oct 2016, 05:38

              @cerr Looks like you have added the groupbox in a layout?
              Can you post the relevant code ?

              C Offline
              C Offline
              cerr
              wrote on 15 Oct 2016, 20:16 last edited by
              #6

              @p3c0 said in how to setAlignment of QGroupBox:

              @cerr Looks like you have added the groupbox in a layout?
              Can you post the relevant code ?

              Correct,

              Okay, so let's see:
              My groupBox is here, in addTerminal() which gets called with a QSplitter as parent... - not sure if that's enough...

              
              Terminal* Session::addTerminal(QWidget* parent)
              {
                  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);    
                  
                  QGroupBox *groupBox = new QGroupBox(tr("Test"), parent);
                  groupBox->setAlignment(Qt::AlignLeft);
                  QWidget* terminalWidget = terminal->terminalWidget();
                  QVBoxLayout *vbox = new QVBoxLayout;
                  vbox->addWidget(terminalWidget);
                  groupBox->setLayout(vbox);
                  terminalWidget ->show();
                  if (/*terminalWidget*/groupBox) /*terminalWidget*/groupBox->setFocus();
                  groupBox->show();
              
                  return terminal;
              }
              

              and then, the constructor for Terminal() looks like this:

              Terminal::Terminal(QWidget* parent) : QObject(parent)
              {
                  m_terminalId = m_availableTerminalId;
                  m_availableTerminalId++;
              
                  m_keyboardInputEnabled = true;
              
                  m_monitorActivityEnabled = false;
                  m_monitorSilenceEnabled = false;
              
                  m_part = NULL;
                  m_terminalInterface = NULL;
                  m_partWidget = NULL;
                  m_terminalWidget = NULL;
                  m_parentSplitter = parent;
              
                  KPluginFactory* factory = 0;
                  KService::Ptr service = KService::serviceByDesktopName("konsolepart");
                  if( service )
                  {
                      factory = KPluginLoader(service->library()).factory();
              
                  m_part = factory ? (factory->create<KParts::Part>(parent)) : 0;
              
                  if (m_part)
                  {
                      connect(m_part, SIGNAL(setWindowCaption(QString)), this, SLOT(setTitle(QString)));
                      connect(m_part, SIGNAL(overrideShortcut(QKeyEvent*,bool&)), this, SLOT(overrideShortcut(QKeyEvent*,bool&)));
                      connect(m_part, SIGNAL(destroyed()), this, SLOT(deleteLater()));
              
                      m_partWidget = m_part->widget();
              
                      m_terminalWidget = m_part->widget()->focusWidget();
              
                      if (m_terminalWidget)
                      {
                          m_terminalWidget->setFocusPolicy(Qt::WheelFocus);
                          m_terminalWidget->installEventFilter(this);
                      }
              
                      disableOffendingPartActions();
              
                      m_terminalInterface = qobject_cast<TerminalInterface*>(m_part);
                      if (m_terminalInterface) m_terminalInterface->showShellInDir(QDir::homePath());
                  }
                  else
                      displayKPartLoadError();
                  }
              }
              
              1 Reply Last reply
              0
              • P Offline
                P Offline
                p3c0
                Moderators
                wrote on 16 Oct 2016, 04:35 last edited by
                #7

                @cerr This part looks odd:

                QVBoxLayout *vbox = new QVBoxLayout;
                vbox->addWidget(terminalWidget);
                groupBox->setLayout(vbox);
                

                You should set layout (vbox) to your main widget and in this layout add widgets groupBox and terminalWidget.

                157

                C 1 Reply Last reply 16 Oct 2016, 05:03
                2
                • P p3c0
                  16 Oct 2016, 04:35

                  @cerr This part looks odd:

                  QVBoxLayout *vbox = new QVBoxLayout;
                  vbox->addWidget(terminalWidget);
                  groupBox->setLayout(vbox);
                  

                  You should set layout (vbox) to your main widget and in this layout add widgets groupBox and terminalWidget.

                  C Offline
                  C Offline
                  cerr
                  wrote on 16 Oct 2016, 05:03 last edited by
                  #8

                  @p3c0 said in how to setAlignment of QGroupBox:

                  @cerr This part looks odd:

                  QVBoxLayout *vbox = new QVBoxLayout;
                  vbox->addWidget(terminalWidget);
                  groupBox->setLayout(vbox);
                  

                  You should set layout (vbox) to your main widget and in this layout add widgets groupBox and terminalWidget.

                  Hmm, I don't get this, so are you saying this should look something like:

                      QVBoxLayout *vbox = new QVBoxLayout;
                      vbox->addWidget(terminalWidget);
                      vbox->addWidget(groupBox);
                      parent->setTerminalLayout(vbox); // vbox->setLayout() would be called within this method
                      terminalWidget ->show();
                      if (groupBox) groupBox->setFocus();
                  

                  but I don't see what a differnce it'll make to call setLayout from within another wrapper , I must not understand you properly - can you clarify, please?

                  Thanks!

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

                    @cerr What I imagined was that you are trying to create a main widget and in that you want to add a groupbox and terminalwidget so I suggested to add this layout(vbox) to the main widget and in that you add these 2 widgets so that they are arranged vertically. Is this the requirement ?

                    157

                    C 1 Reply Last reply 16 Oct 2016, 05:17
                    0
                    • P p3c0
                      16 Oct 2016, 05:11

                      @cerr What I imagined was that you are trying to create a main widget and in that you want to add a groupbox and terminalwidget so I suggested to add this layout(vbox) to the main widget and in that you add these 2 widgets so that they are arranged vertically. Is this the requirement ?

                      C Offline
                      C Offline
                      cerr
                      wrote on 16 Oct 2016, 05:17 last edited by
                      #10

                      @p3c0 said in how to setAlignment of QGroupBox:

                      @cerr What I imagined was that you are trying to create a main widget and in that you want to add a groupbox and terminalwidget so I suggested to add this layout(vbox) to the main widget and in that you add these 2 widgets so that they are arranged vertically. Is this the requirement ?

                      By main widget you understand a "mother widget" that would contain the groupbox & the terminal widget, right? What I want to do is, to nest the terminalwidget within a groupbox so that there is an ability to assign the terminalwidget some kind of membership (that makes visually sense, too). If you have a better idea on how to solve this, please don't be shy to let me know! Thanks!

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

                        @cerr

                        By main widget you understand a "mother widget" that would contain the groupbox & the terminal widget, right?

                        Yes.

                        So now where do you add this groupbox ? You should add this groupbox inside another layout so that it is laid properly.

                        157

                        C 1 Reply Last reply 16 Oct 2016, 05:33
                        1
                        • P p3c0
                          16 Oct 2016, 05:24

                          @cerr

                          By main widget you understand a "mother widget" that would contain the groupbox & the terminal widget, right?

                          Yes.

                          So now where do you add this groupbox ? You should add this groupbox inside another layout so that it is laid properly.

                          C Offline
                          C Offline
                          cerr
                          wrote on 16 Oct 2016, 05:33 last edited by
                          #12

                          @p3c0 said in how to setAlignment of QGroupBox:

                          Yes.

                          So now where do you add this groupbox ? You should add this groupbox inside another layout so that it is laid properly.

                          So I currently have something lke groupBox(vbox(terminalWidget())) and I think from what you're saying, I should have something like ContainerWidget(vbox(groupBox(terminalWidget))), is that correct? Any idea what kind of container widget I can use for this? Or better, vbox(groupBox(terminalWidget)) should do as well, shouldn't it?

                          C 1 Reply Last reply 16 Oct 2016, 05:42
                          0
                          • P Offline
                            P Offline
                            p3c0
                            Moderators
                            wrote on 16 Oct 2016, 05:38 last edited by
                            #13

                            @cerr

                            ContainerWidget(vbox(groupBox(terminalWidget))), is that correct?

                            Yes. You can use QDialog as the container widget.

                            157

                            1 Reply Last reply
                            0
                            • C cerr
                              16 Oct 2016, 05:33

                              @p3c0 said in how to setAlignment of QGroupBox:

                              Yes.

                              So now where do you add this groupbox ? You should add this groupbox inside another layout so that it is laid properly.

                              So I currently have something lke groupBox(vbox(terminalWidget())) and I think from what you're saying, I should have something like ContainerWidget(vbox(groupBox(terminalWidget))), is that correct? Any idea what kind of container widget I can use for this? Or better, vbox(groupBox(terminalWidget)) should do as well, shouldn't it?

                              C Offline
                              C Offline
                              cerr
                              wrote on 16 Oct 2016, 05:42 last edited by cerr
                              #14

                              @p3c0 said in how to setAlignment of QGroupBox:

                              @cerr

                              ContainerWidget(vbox(groupBox(terminalWidget))), is that correct?

                              Yes. You can use QDialog as the container widget.

                              But I don't want it to be in abother dialog and it already is in a QTabWidget....I should use that as the outer most layer probably...

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

                                @cerr Ok. But remember to add that groupbox inside a layout.

                                157

                                C 1 Reply Last reply 16 Oct 2016, 05:52
                                0
                                • P p3c0
                                  16 Oct 2016, 05:50

                                  @cerr Ok. But remember to add that groupbox inside a layout.

                                  C Offline
                                  C Offline
                                  cerr
                                  wrote on 16 Oct 2016, 05:52 last edited by
                                  #16

                                  @p3c0 said in how to setAlignment of QGroupBox:

                                  @cerr Ok. But remember to add that groupbox inside a layout.

                                  So what actually happens in my application is:
                                  MainWindow->QTabWidget->session->setupSession->addTerminal->QVBoxWidget(QGroupBox->terminalWidget) and you suggest i'd better be like mainwindow->QVBoxWidget(QTabWidget->session->setupSession->addTerminal->QGroupBox->terminalWidget) ?
                                  Will that change things?

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

                                    @cerr No. The earlier one.
                                    MainWindow->QTabWidget->session->setupSession->addTerminal->QVBoxWidget(QGroupBox->terminalWidget)

                                    But I dont see that happening in your original code.

                                    QGroupBox *groupBox = new QGroupBox(tr("Test"), parent); //<--- This should be added in a layout too.
                                    groupBox->setAlignment(Qt::AlignLeft);
                                    
                                    QWidget* terminalWidget = terminal->terminalWidget();
                                    
                                    QVBoxLayout *vbox = new QVBoxLayout;
                                    vbox->addWidget(terminalWidget);
                                    groupBox->setLayout(vbox); // <--- This sets layout inside it
                                    
                                    terminalWidget ->show();
                                    if (/*terminalWidget*/groupBox) /*terminalWidget*/groupBox->setFocus();
                                       groupBox->show();
                                    

                                    157

                                    C 1 Reply Last reply 16 Oct 2016, 06:01
                                    0
                                    • P p3c0
                                      16 Oct 2016, 05:58

                                      @cerr No. The earlier one.
                                      MainWindow->QTabWidget->session->setupSession->addTerminal->QVBoxWidget(QGroupBox->terminalWidget)

                                      But I dont see that happening in your original code.

                                      QGroupBox *groupBox = new QGroupBox(tr("Test"), parent); //<--- This should be added in a layout too.
                                      groupBox->setAlignment(Qt::AlignLeft);
                                      
                                      QWidget* terminalWidget = terminal->terminalWidget();
                                      
                                      QVBoxLayout *vbox = new QVBoxLayout;
                                      vbox->addWidget(terminalWidget);
                                      groupBox->setLayout(vbox); // <--- This sets layout inside it
                                      
                                      terminalWidget ->show();
                                      if (/*terminalWidget*/groupBox) /*terminalWidget*/groupBox->setFocus();
                                         groupBox->show();
                                      
                                      C Offline
                                      C Offline
                                      cerr
                                      wrote on 16 Oct 2016, 06:01 last edited by
                                      #18

                                      @p3c0 said in how to setAlignment of QGroupBox:

                                      @cerr No. The earlier one.
                                      MainWindow->QTabWidget->session->setupSession->addTerminal->QVBoxWidget(QGroupBox->terminalWidget)

                                      But I dont see that happening in your original code.

                                      QGroupBox *groupBox = new QGroupBox(tr("Test"), parent); //<--- This should be added in a layout too.
                                      groupBox->setAlignment(Qt::AlignLeft);
                                      
                                      QWidget* terminalWidget = terminal->terminalWidget();
                                      
                                      QVBoxLayout *vbox = new QVBoxLayout;
                                      vbox->addWidget(terminalWidget);
                                      groupBox->setLayout(vbox); // <--- This sets layout inside it
                                      
                                      terminalWidget ->show();
                                      if (/*terminalWidget*/groupBox) /*terminalWidget*/groupBox->setFocus();
                                         groupBox->show();
                                      

                                      Sorry,

                                      Yeah, I had changed it in the meantime to:

                                          QGroupBox *groupBox = new QGroupBox(tr("Test"), parent);
                                          groupBox->setAlignment(Qt::AlignLeft);
                                          QWidget* terminalWidget = terminal->terminalWidget();
                                          QVBoxLayout *vbox = new QVBoxLayout;
                                          vbox->addWidget(terminalWidget);
                                          vbox->addWidget(groupBox);
                                          //groupBox->setLayout(vbox);  <- if i remove the comment, it won't start my application at all...
                                          terminalWidget ->show();
                                          if (/*terminalWidget*/groupBox) /*terminalWidget*/groupBox->setFocus();
                                      
                                      1 Reply Last reply
                                      0
                                      • 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

                                          1/31

                                          15 Oct 2016, 04:23

                                          • Login

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