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. Help with QFormLayout

Help with QFormLayout

Scheduled Pinned Locked Moved General and Desktop
15 Posts 3 Posters 8.4k 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.
  • E Offline
    E Offline
    Exotic_Devel
    wrote on 4 Jul 2011, 17:05 last edited by
    #1

    QFormLayout I am using to display a registration screen, my problem is that all fields (QLineEdits) are the same size and being redimenssionados along with the window. QLineEdits for displaying dates, for example, does not have an exact size, because only display a date (dd / mm / yyyy). I also think that these fields need not be resized with the layout, because the number of displayed characters is small.
    example:

    @#ifndef MDICHILDCLIENTE_H
    #define MDICHILDCLIENTE_H

    #include <QWidget>
    #include <QTableView>
    #include <QMenu>
    #include <QMenuBar>
    #include <QAction>
    #include <QLineEdit>
    #include <QLabel>
    #include <QPushButton>
    #include <QFormLayout>
    #include <QVBoxLayout>
    #include <QHBoxLayout>

    class MdiChildClientes : public QWidget
    {

    public:

    static MdiChildClientes* getInstance();
    

    private:

    MdiChildClientes(QWidget *parent = 0);
    
    QTableView *tableview;
    QMenuBar *menubar;
    QMenu *editar;
    QMenu *colunas;
    QMenu *ajuda;
    
    QAction *filtrar;
    QAction *qacodigo;
    QAction *qanome;
    QAction *qatelefone;
    QAction *qacelular;
    QAction *qaemail;
    QAction *qarg;
    QAction *qacpf;
    QAction *qanascimento;
    QAction *qasexo;
    QAction *qaultcompra;
    QAction *manual;
    QAction *sobre;
    QLineEdit *qlenome;
    QLineEdit *qlecep;
    QLineEdit *qleendnumero;
    QLineEdit *qlelogradouro;
    QLineEdit *qlecidade;
    QLineEdit *qlebairro;
    QLineEdit *qleestado;
    QLineEdit *qletelefone;
    QLineEdit *qlecelular;
    QLineEdit *qleemail;
    QLineEdit *qlerg;
    QLineEdit *qlecpf;
    QLineEdit *qlenascimento;
    QLineEdit *qlesexo;
    QLineEdit *qleultcompra;
    QLineEdit *qlelocalizar;
    QPushButton *qpblocalizar;
    QPushButton *qpbsalvar;
    QPushButton *qpbexcluir;
    QPushButton *qpbbnovo;
    
    QFormLayout *formlayout;
    QVBoxLayout *vboxlayout;
    QHBoxLayout *hboxlayout_1;
    QHBoxLayout *hboxlayout_2;
    QHBoxLayout *hboxlayout_3;
    
    void createLineEdits();
    void createButtons();
    void createMenus();
    void createTableView();
    void montaLayouts();
    
    ~MdiChildClientes();
    

    };

    static MdiChildClientes *objmdichicli;

    #endif // MDICHILDCLIENTE_H
    @

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Exotic_Devel
      wrote on 4 Jul 2011, 17:05 last edited by
      #2

      .cpp

      @#include "MdiChildClientes.h"

      MdiChildClientes::MdiChildClientes(QWidget *parent) : QWidget(parent)
      {
      setWindowTitle("Registro de Clientes");
      setWindowIcon(QIcon(":/icoclientes"));
      setAttribute(Qt::WA_DeleteOnClose);

      /* Inicializa os Layouts */
      hboxlayout_1 = new QHBoxLayout(this);
      vboxlayout = new QVBoxLayout;
      hboxlayout_2 = new QHBoxLayout;
      hboxlayout_3 = new QHBoxLayout;
      formlayout = new QFormLayout;
      formlayout->setLabelAlignment(Qt::AlignRight);
      
      createMenus(); // Cria os menus da janela
      createTableView(); // Cria a TableView (DataGRid)
      createButtons(); // Cria os botões de ação;
      createLineEdits(); // Cria as linhas de edição
      montaLayouts(); // Monta o Layout da janela
      

      }

      MdiChildClientes* MdiChildClientes::getInstance()
      {
      if(!objmdichicli)
      objmdichicli = new MdiChildClientes;

          return objmdichicli;
      

      }

      void MdiChildClientes::createMenus()
      {
      menubar = new QMenuBar(this); // Barra de menus

      editar = menubar->addMenu("&Editar"); // Menus
      ajuda = menubar->addMenu("&Ajuda");
      colunas = editar->addMenu("Colunas");
      
      /* Itens de Menus */
      filtrar = editar->addAction("Filtrar");
      
      qacodigo = colunas->addAction("Código");
      qacodigo->setCheckable(true);
      
      qanome = colunas->addAction("Nome");
      qanome->setCheckable(true);
      qanome->setChecked(true);
      
      qatelefone = colunas->addAction("Telefone");
      qatelefone->setCheckable(true);
      
      qacelular = colunas->addAction("Celular");
      qacelular->setCheckable(true);
      
      qaemail = colunas->addAction("Email");
      qaemail->setCheckable(true);
      
      qarg = colunas->addAction("RG");
      qarg->setCheckable(true);
      
      qacpf = colunas->addAction("CPF");
      qacpf->setCheckable(true);
      
      qanascimento = colunas->addAction("Nascimento");
      qanascimento->setCheckable(true);
      
      qasexo = colunas->addAction("Sexo");
      qasexo->setCheckable(true);
      
      qaultcompra = colunas->addAction("Ult.Compra");
      qaultcompra->setCheckable(true);
      
      manual = ajuda->addAction(QIcon(":/icomanual"),"Manual");
      sobre = ajuda->addAction("Sobre...");
      
      this->layout()->setMenuBar(menubar);
      

      }

      void MdiChildClientes::createTableView()
      {
      tableview = new QTableView(this);
      }

      void MdiChildClientes::createButtons()
      {
      qpbsalvar = new QPushButton("Salvar", tableview);
      qpbexcluir = new QPushButton("Excluir", tableview);
      qpbbnovo = new QPushButton("Novo", tableview);
      qpblocalizar = new QPushButton(QIcon(":/icolocaliza"),"", tableview);
      }

      void MdiChildClientes::createLineEdits()
      {
      qlelocalizar = new QLineEdit(tableview);
      qlenome = new QLineEdit(this);
      qlecep = new QLineEdit(this);
      qleendnumero = new QLineEdit(this);
      qlelogradouro = new QLineEdit(this);
      qlecidade = new QLineEdit(this);
      qlebairro = new QLineEdit(this);
      qleestado = new QLineEdit(this);
      qletelefone = new QLineEdit(this);
      qlecelular = new QLineEdit(this);
      qleemail = new QLineEdit(this);
      qlerg = new QLineEdit(this);
      qlecpf = new QLineEdit(this);
      qlenascimento = new QLineEdit(this);
      qlesexo = new QLineEdit(this);
      qleultcompra = new QLineEdit(this);
      qleultcompra->setEnabled(false);
      }

      void MdiChildClientes::montaLayouts()
      {
      vboxlayout->addWidget(tableview);
      hboxlayout_2->addWidget(qpbsalvar);
      hboxlayout_2->addWidget(qpbexcluir);
      hboxlayout_2->addWidget(qpbbnovo);
      hboxlayout_3->addWidget(qlelocalizar);
      hboxlayout_3->addWidget(qpblocalizar);

      formlayout->addRow("Nome", qlenome);
      formlayout->addRow("Cep", qlecep);
      formlayout->addRow("Número",qleendnumero);
      formlayout->addRow("Logradouro", qlelogradouro);
      formlayout->addRow("Cidade", qlecidade);
      formlayout->addRow("Bairro", qlebairro);
      formlayout->addRow("Estado", qleestado);
      formlayout->addRow("Telefone", qletelefone);
      formlayout->addRow("Celular", qlecelular);
      formlayout->addRow("Email", qleemail);
      formlayout->addRow("RG", qlerg);
      formlayout->addRow("CPF", qlecpf);
      formlayout->addRow("Nascimento", qlenascimento);
      formlayout->addRow("Sexo", qlesexo);
      formlayout->addRow("Ult. Compra", qleultcompra);
      
      vboxlayout->addLayout(hboxlayout_2);
      vboxlayout->addLayout(hboxlayout_3);
      hboxlayout_1->addLayout(vboxlayout);
      hboxlayout_1->addLayout(formlayout);
      

      }

      MdiChildClientes::~MdiChildClientes()
      {

      }
      @

      Running QLineEdits see that all are the same size, and I do not want so, QLineEdit "Nascimento" need not be the same size of the "Nome", because that date has fewer characters a name. The layout tb is displaying the small window, and need to resize with the mouse, how do I determine the initial window size

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Exotic_Devel
        wrote on 4 Jul 2011, 18:01 last edited by
        #3

        Ok, I found a part to set the maximum size of a QLineEdit is with setMaximumSize. Now what we have not figured out is how to define the size of the window unicial note that I am referring to the initial size, and no fixed size, the initial size is the size that the window should appear when vor call, but you can resize with mouse

        1 Reply Last reply
        0
        • E Offline
          E Offline
          Exotic_Devel
          wrote on 5 Jul 2011, 11:43 last edited by
          #4

          Anyone? :-(

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Eddy
            wrote on 5 Jul 2011, 13:34 last edited by
            #5

            I don't know if i understand you correctly.

            maybe spacers are an option?

            could you show us a picture of what you want? and how it is now?

            Qt Certified Specialist
            www.edalsolutions.be

            1 Reply Last reply
            0
            • E Offline
              E Offline
              Exotic_Devel
              wrote on 5 Jul 2011, 15:10 last edited by
              #6

              I do not want to prevent resizing, I just want to open the window like the image that is edited, however if the user resizes it he can. Once this window is called it appears as the original image, notice that the window is narrow and all the fields appear the same size, the field "Estado" will be entered only where the abbreviations of the states, SP, MG, RS, etc.. .. Is the same size of the field "Nome" that you may receive up to 50 characters, is disproportionate. To solve the problem of the size of the fields I used setMaximumWidth (int) to set the maximum size (width) of the QLineEdit, but do not know if this is the correct way.
              What was I still could not make the open window as the size of the edited image. I edited the image resized with the mouse after it opened, but I want her to have open at that size. I've tried setSize setGeometry, without success.

              !http://forum.qtbrasil.com/download/file.php?id=67(Edited picture)!

              !http://forum.qtbrasil.com/download/file.php?id=66(Original Image)!

              Thanks for the help friend

              1 Reply Last reply
              0
              • E Offline
                E Offline
                Eddy
                wrote on 5 Jul 2011, 16:07 last edited by
                #7

                You could use a combination of setminimumsizehint and a spacer for each row except the biggest one.

                Like this (without the left part, to make my description simple):
                Row 1 : hlayout : nome + lineedit (setminimumsizehint = 50)
                Row 2 : hlayout :cep + linedi (setminimumsizehint = 15) + spacer
                row 3 ....
                .....

                Qt Certified Specialist
                www.edalsolutions.be

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  ludde
                  wrote on 5 Jul 2011, 16:49 last edited by
                  #8

                  Did you have a look at the fieldGrowthPolicy property?

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    Exotic_Devel
                    wrote on 5 Jul 2011, 17:50 last edited by
                    #9

                    Actually what I need right now and set the initial window size. I'm trying to setGeometry, but ignores the window, perhaps because I'm using Layouts. I set the initial window size, but do not want to prevent the user can resize.
                    For QLineEdits QLabels and am using QFormLayout. Below is a picture showing how to structure my layouts.

                    !http://forum.qtbrasil.com/download/file.php?id=69(Structure Layout)!

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      ludde
                      wrote on 5 Jul 2011, 18:07 last edited by
                      #10

                      What do you mean "ignores the window"? You should be able to set the geometry of the window, i.e. the widget that contains the top level layout. You should not use setGeometry on things inside a layout.

                      Of course, if the contents of the window does not allow the geometry you are setting it to, it will be as small/large is it can, but not exactly what you set it to.

                      1 Reply Last reply
                      0
                      • E Offline
                        E Offline
                        Exotic_Devel
                        wrote on 5 Jul 2011, 18:27 last edited by
                        #11

                        I am using setGeometry in the class constructor. But nothing changes.

                        1 Reply Last reply
                        0
                        • E Offline
                          E Offline
                          Eddy
                          wrote on 6 Jul 2011, 08:14 last edited by
                          #12

                          i've made a simple ui file for you to look into :
                          "link ":http://dl.dropbox.com/u/33544011/dialog.ui

                          I followed the principle using spacers

                          hope this helps.

                          Qt Certified Specialist
                          www.edalsolutions.be

                          1 Reply Last reply
                          0
                          • E Offline
                            E Offline
                            Exotic_Devel
                            wrote on 6 Jul 2011, 10:57 last edited by
                            #13

                            Eddy, thanks for the example, but what I need now is to figure out how to set an initial size for the window.
                            I'm not using designer in this work, I am working on the arm.
                            I took a look at the code generated by the designer in the example you sent, but could not understand the code.

                            @class Ui_Dialog
                            {
                            public:
                            QGridLayout *gridLayout;
                            QListView *listView;
                            QVBoxLayout *verticalLayout;
                            QHBoxLayout *horizontalLayout;
                            QLabel *label;
                            QLineEdit *lineEdit;
                            QHBoxLayout *horizontalLayout_2;
                            QLabel *label_2;
                            QLineEdit *lineEdit_2;
                            QSpacerItem *horizontalSpacer;
                            QHBoxLayout *horizontalLayout_3;
                            QLabel *label_3;
                            QLineEdit *lineEdit_3;
                            QSpacerItem *horizontalSpacer_2;
                            QSpacerItem *verticalSpacer;

                            void setupUi(QDialog *Dialog)
                            {
                                if (Dialog->objectName().isEmpty())
                                    Dialog->setObjectName(QString::fromUtf8("Dialog"));
                                Dialog->resize(475, 129);
                                gridLayout = new QGridLayout(Dialog);
                                gridLayout->setSpacing(6);
                                gridLayout->setContentsMargins(11, 11, 11, 11);
                                gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
                                listView = new QListView(Dialog);
                                listView->setObjectName(QString::fromUtf8("listView"));
                            
                                gridLayout->addWidget(listView, 0, 0, 1, 1);
                            
                                verticalLayout = new QVBoxLayout();
                                verticalLayout->setSpacing(6);
                                verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
                                horizontalLayout = new QHBoxLayout();
                                horizontalLayout->setSpacing(6);
                                horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
                                label = new QLabel(Dialog);
                                label->setObjectName(QString::fromUtf8("label"));
                            
                                horizontalLayout->addWidget(label);
                            
                                lineEdit = new QLineEdit(Dialog);
                                lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
                                lineEdit->setMinimumSize(QSize(0, 0));
                                lineEdit->setMaximumSize(QSize(16777215, 16777215));
                            
                                horizontalLayout->addWidget(lineEdit);
                            
                            
                                verticalLayout->addLayout(horizontalLayout);
                            
                                horizontalLayout_2 = new QHBoxLayout();
                                horizontalLayout_2->setSpacing(6);
                                horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
                                label_2 = new QLabel(Dialog);
                                label_2->setObjectName(QString::fromUtf8("label_2"));
                            
                                horizontalLayout_2->addWidget(label_2);
                            
                                lineEdit_2 = new QLineEdit(Dialog);
                                lineEdit_2->setObjectName(QString::fromUtf8("lineEdit_2"));
                                lineEdit_2->setMinimumSize(QSize(0, 0));
                            
                                horizontalLayout_2->addWidget(lineEdit_2);
                            
                                horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
                            
                                horizontalLayout_2->addItem(horizontalSpacer);
                            
                            
                                verticalLayout->addLayout(horizontalLayout_2);
                            
                                horizontalLayout_3 = new QHBoxLayout();
                                horizontalLayout_3->setSpacing(6);
                                horizontalLayout_3->setObjectName(QString::fromUtf8("horizontalLayout_3"));
                                label_3 = new QLabel(Dialog);
                                label_3->setObjectName(QString::fromUtf8("label_3"));
                            
                                horizontalLayout_3->addWidget(label_3);
                            
                                lineEdit_3 = new QLineEdit(Dialog);
                                lineEdit_3->setObjectName(QString::fromUtf8("lineEdit_3"));
                            
                                horizontalLayout_3->addWidget(lineEdit_3);
                            
                                horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
                            
                                horizontalLayout_3->addItem(horizontalSpacer_2);
                            
                            
                                verticalLayout->addLayout(horizontalLayout_3);
                            
                                verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
                            
                                verticalLayout->addItem(verticalSpacer);
                            
                            
                                gridLayout->addLayout(verticalLayout, 0, 1, 1, 1);
                            
                                gridLayout->setColumnStretch(1, 1);
                            
                                retranslateUi(Dialog);
                            
                                QMetaObject::connectSlotsByName(Dialog);
                            } // setupUi
                            

                            };

                            namespace Ui {
                            class Dialog: public Ui_Dialog {};
                            } // namespace Ui@

                            The class Ui_Dialog does not use inheritance, and sets the window size in QDialog object passed as parameter.
                            The correct way would be to inherit from QDialog?:

                            class Ui_Dialog : public QDialog

                            and set the window size in the constructor, by calling a resize (x, y)?

                            1 Reply Last reply
                            0
                            • E Offline
                              E Offline
                              Eddy
                              wrote on 6 Jul 2011, 12:21 last edited by
                              #14

                              I don't understand what you want. you say you don't want to use ui but you ask how to use it?

                              I you want to understand how to use the ui file, then you can simply use the wizard to create a new widget based project with QDialog and everything is set up for you. copy paste and you're done.
                              If you search the docs the principle is well explained there.

                              to control the size of your window you could use resize:
                              @int main(int argc, char *argv[])
                              {
                              QApplication a(argc, argv);
                              Dialog w;

                              w.resize(300,300);
                              w.show();
                              
                              return a.exec&#40;&#41;;
                              

                              }@

                              Qt Certified Specialist
                              www.edalsolutions.be

                              1 Reply Last reply
                              0
                              • E Offline
                                E Offline
                                Exotic_Devel
                                wrote on 6 Jul 2011, 12:43 last edited by
                                #15

                                I did not ask how to use UI, I just tried to understand the code generated by the UI designer to be able to find the solution to my problem.
                                See my code up there is a class that inherits from QWidget and is displayed in a QMdiArea.

                                @void WindowMain::evoqueSubWindClientes()
                                {
                                QWidget *subwincli = new MdiChildClientes(this);
                                mdiarea->addSubWindow(subwincli);
                                subwincli->resize(800,600);
                                subwincli->show();
                                }@

                                But the command resize (800,600) does not have any effect.

                                1 Reply Last reply
                                0

                                4/15

                                5 Jul 2011, 11:43

                                topic:navigator.unread, 11
                                • Login

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