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 type an interface without a ui editor ??
QtWS25 Last Chance

how to type an interface without a ui editor ??

Scheduled Pinned Locked Moved Solved General and Desktop
ui form
7 Posts 2 Posters 413 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.
  • T Offline
    T Offline
    timob256
    wrote on 26 Nov 2021, 13:26 last edited by timob256
    #1

    The examples are very complex and I understood them.

    can't run in display

    #ifndef DIALOGOKNO_H
    #define DIALOGOKNO_H
    
    #include <QMainWindow>
    #include <QFile>
    #include <QPushButton>
    #include <QLabel>
    #include <QSize>
    
    #include <QApplication>
    #include <QDesktopWidget>
    #include <QRect>
    #include <QDebug>
    #include <QLineEdit>
    #include <QGridLayout>
    #include <QSpacerItem>
    
    class DialogOkno : public QWidget
    {
        Q_OBJECT
    
    public:
        DialogOkno(QWidget *parent = 0);
        ~DialogOkno();
    
    protected:
    //    QWidget* centralWidget;
    
        QFile* file;         // загрузить файл
        QGridLayout* gl_layaout[3];
        QPushButton* b_load; // кнопка для выбора и загрузки файла
        QLabel* l_label[3];
        QLineEdit* le_edit[7];
        QSpacerItem* si_spacer[4];
    };
    
    #endif // DIALOGOKNO_H
    
    
    #include "dialogokno.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        DialogOkno w;
    
        QDesktopWidget desktop;
        QRect rect = desktop.availableGeometry(desktop.primaryScreen()); // прямоугольник с размерами экрана
        QPoint center = rect.center(); //координаты центра экрана
    
        qDebug() << "rect.x()/2 " <<rect.y()/2  << "rect.y()/2" << rect.y()/2;
        qDebug() << "center.x()/2 " <<center.y()  << "center.y()/2" << center.y();
    
        w.resize(center.x(), center.y());
        w.setWindowTitle("программа");
        w.show();
    
        return a.exec();
    }
    
    
    
    #include "dialogokno.h"
    
    DialogOkno::DialogOkno(QWidget *parent)
        : QWidget(parent)
    {
     
        // обявл элементы
    
        gl_layaout[0] = new QGridLayout(parent);
        gl_layaout[1] = new QGridLayout(parent);
        gl_layaout[2] = new QGridLayout(parent);
    
        l_label[0] = new QLabel(parent);
        l_label[1] = new QLabel(parent);
        l_label[2] = new QLabel(parent);
    
        le_edit[0] = new QLineEdit(parent);
        le_edit[1] = new QLineEdit(parent);
        le_edit[2] = new QLineEdit(parent);
        le_edit[3] = new QLineEdit(parent);
        le_edit[4] = new QLineEdit(parent);
        le_edit[5] = new QLineEdit(parent);
        le_edit[6] = new QLineEdit(parent);
    
        // настройки элеметов (стилизация)
    
        // заполнение элементов
        l_label[0]->setText("hla_global");
        l_label[1]->setText("hla_local");
        l_label[2]->setText("logger");
    
        le_edit[0]->setText("server_ip_global");
        le_edit[1]->setText("server_port_global");
    
        le_edit[2]->setText("server_port_local");
        le_edit[3]->setText("server_port_local");
    
        le_edit[4]->setText("log");
        le_edit[5]->setText("log_period_ms");
        le_edit[6]->setText("log_size_in_mb");
    
        //разложение элементов по группам
    
        gl_layaout[0]->addWidget(l_label[0],0, 0, 1, 1);
        gl_layaout[0]->addWidget(le_edit[0],1, 0, 1, 1);
        gl_layaout[0]->addWidget(le_edit[1],2, 0, 1, 1);
    
        gl_layaout[1]->addWidget(l_label[1],0, 0, 1, 1);
        gl_layaout[1]->addWidget(le_edit[2],1, 0, 1, 1);
        gl_layaout[1]->addWidget(le_edit[3],2, 0, 1, 1);
    
        gl_layaout[2]->addWidget(l_label[2],0, 0, 1, 1);
        gl_layaout[2]->addWidget(le_edit[4],1, 0, 1, 1);
        gl_layaout[2]->addWidget(le_edit[5],2, 0, 1, 1);
        gl_layaout[2]->addWidget(le_edit[6],3, 0, 1, 1);
        
    
    
       this->setLayout(gl_layaout[0]);
    
    //    this->addLayout(gridLayout, 0, 0, 1, 1);
    
        si_spacer[0] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
    
        this->setLayout(si_spacer[0]);
    
    //    gridLayout_4->addItem(horizontalSpacer_2, 0, 1, 1, 1);
    
    //    gridLayout_4->addLayout(gridLayout_3, 0, 2, 1, 1);
    
        si_spacer[1] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
    
    //    gridLayout_4->addItem(horizontalSpacer, 0, 3, 1, 1);
    
        si_spacer[2] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding);
    
    //    gridLayout_4->addItem(verticalSpacer, 1, 0, 1, 1);
    
    //    gridLayout_4->addLayout(gridLayout_2, 2, 0, 1, 1);
    
        si_spacer[3] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding);
    
    //    gridLayout_4->addItem(verticalSpacer_2, 3, 0, 1, 1);
    
    
     
    }
    
    DialogOkno::~DialogOkno()
    {
    
    }
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on 26 Nov 2021, 14:11 last edited by
      #2

      You forgot to add the second and the third layouts to the first one.

          gl_layaout[0] = new QGridLayout(parent);
          gl_layaout[1] = new QGridLayout(parent);
          gl_layaout[2] = new QGridLayout(parent);
          
          // add them here
          gl_layaout[0]->addLayout(gl_layaout[1],0,0);
          gl_layaout[0]->addLayout(gl_layaout[2],0,1);
      
      1 Reply Last reply
      2
      • T Offline
        T Offline
        timob256
        wrote on 26 Nov 2021, 14:18 last edited by
        #3

        @mpergand said in how to type an interface without a ui editor ??:

        You forgot to add the second and the third layouts to the first one.

        DialogOkno::DialogOkno(QWidget *parent)
            : QWidget(parent)
        {
            // обявл элементы
            gl_layaout[0] = new QGridLayout(parent);
            gl_layaout[1] = new QGridLayout(parent);
            gl_layaout[2] = new QGridLayout(parent);
        
            gl_layaout[3] = new QGridLayout(parent);
        
        
            l_label[0] = new QLabel(parent);
            l_label[1] = new QLabel(parent);
            l_label[2] = new QLabel(parent);
        
            le_edit[0] = new QLineEdit(parent);
            le_edit[1] = new QLineEdit(parent);
            le_edit[2] = new QLineEdit(parent);
            le_edit[3] = new QLineEdit(parent);
            le_edit[4] = new QLineEdit(parent);
            le_edit[5] = new QLineEdit(parent);
            le_edit[6] = new QLineEdit(parent);
        
            // настройки элеметов (стилизация)
        
            // заполнение элементов
            l_label[0]->setText("hla_global");
            l_label[1]->setText("hla_local");
            l_label[2]->setText("logger");
        
            le_edit[0]->setText("server_ip_global");
            le_edit[1]->setText("server_port_global");
        
            le_edit[2]->setText("server_port_local");
            le_edit[3]->setText("server_port_local");
        
            le_edit[4]->setText("log");
            le_edit[5]->setText("log_period_ms");
            le_edit[6]->setText("log_size_in_mb");
        
            //разложение элементов по группам
        
            gl_layaout[0]->addWidget(l_label[0], 0, 0, 1, 1);
            gl_layaout[0]->addWidget(le_edit[0], 1, 0, 1, 1);
            gl_layaout[0]->addWidget(le_edit[1], 2, 0, 1, 1);
        
            gl_layaout[1]->addWidget(l_label[1], 0, 0, 1, 1);
            gl_layaout[1]->addWidget(le_edit[2], 1, 0, 1, 1);
            gl_layaout[1]->addWidget(le_edit[3], 2, 0, 1, 1);
        
            gl_layaout[2]->addWidget(l_label[2], 0, 0, 1, 1);
            gl_layaout[2]->addWidget(le_edit[4], 1, 0, 1, 1);
            gl_layaout[2]->addWidget(le_edit[5], 2, 0, 1, 1);
            gl_layaout[2]->addWidget(le_edit[6], 3, 0, 1, 1);
        
        
            gl_layaout[3]->addWidget(gl_layaout[0], 0,0,);
            si_spacer[0] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
            gl_layaout[3]->addWidget(si_spacer[0], 0,1);
            gl_layaout[3]->addWidget(gl_layaout[1], 0,2);
            si_spacer[1] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
            gl_layaout[3]->addWidget(si_spacer[1], 0,3);
            si_spacer[2] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding);
            gl_layaout[3]->addWidget(si_spacer[2], 1,0);
            gl_layaout[3]->addWidget(gl_layaout[2], 2,0);
            si_spacer[3] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding);
            gl_layaout[3]->addWidget(si_spacer[3], 3,0);
        
        
           this->setLayout(gl_layaout[3]);
        }
        

        /home/dima/dima_project/dialog_okno_qmake/dialogokno.cpp:59: ошибка: no matching function for call to ‘QGridLayout::addWidget(QGridLayout*&, int, int)’
        gl_layaout[3]->addWidget(gl_layaout[0], 0,0);
        ^

        /home/dima/dima_project/dialog_okno_qmake/dialogokno.cpp:61: ошибка: no matching function for call to ‘QGridLayout::addWidget(QSpacerItem*&, int, int)’
        gl_layaout[3]->addWidget(si_spacer[0], 0,1);
        ^

        /home/dima/dima_project/dialog_okno_qmake/dialogokno.cpp:62: ошибка: no matching function for call to ‘QGridLayout::addWidget(QGridLayout*&, int, int)’
        gl_layaout[3]->addWidget(gl_layaout[1], 0,2);
        ^

        /home/dima/dima_project/dialog_okno_qmake/dialogokno.cpp:64: ошибка: no matching function for call to ‘QGridLayout::addWidget(QSpacerItem*&, int, int)’
        gl_layaout[3]->addWidget(si_spacer[1], 0,3);
        ^

        /home/dima/dima_project/dialog_okno_qmake/dialogokno.cpp:66: ошибка: no matching function for call to ‘QGridLayout::addWidget(QSpacerItem*&, int, int)’
        gl_layaout[3]->addWidget(si_spacer[2], 1,0);
        ^

        /home/dima/dima_project/dialog_okno_qmake/dialogokno.cpp:67: ошибка: no matching function for call to ‘QGridLayout::addWidget(QGridLayout*&, int, int)’
        gl_layaout[3]->addWidget(gl_layaout[2], 2,0);
        ^

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mpergand
          wrote on 26 Nov 2021, 14:30 last edited by mpergand
          #4

          /home/dima/dima_project/dialog_okno_qmake/dialogokno.cpp:59: ошибка: no matching function for call to ‘QGridLayout::addWidget(QGridLayout*&, int, int)’
          gl_layaout[3]->addWidget(gl_layaout[0], 0,0);
          ^

          Obviously a layout is not a widget ...

          I don't understand what you trying to do with the spacers.

          Construct the interface you want in QDesigner and post a screenshot of it here.
          I will try to reproduce it with code only.

          1 Reply Last reply
          1
          • T Offline
            T Offline
            timob256
            wrote on 26 Nov 2021, 14:46 last edited by
            #5

            @mpergand thanks for the help :3

            i traing mace this Screenshot_20211126_173919.png

            only mace this :( Screenshot_20211126_173649.png

            ```
            

            gl_layaout[3]->addLayout(gl_layaout[0], 0,0);
            si_spacer[0] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
            gl_layaout[3]->addWidget(si_spacer[0], 0, 1, 1, 1);
            gl_layaout[3]->addLayout(gl_layaout[1], 0,2);
            si_spacer[1] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
            gl_layaout[3]->addWidget(si_spacer[1], 0,3, 1, 1);
            si_spacer[2] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding);
            gl_layaout[3]->addWidget(si_spacer[2], 1,0, 1, 1);
            gl_layaout[3]->addLayout(gl_layaout[2], 2,0);
            si_spacer[3] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding);
            gl_layaout[3]->addWidget(si_spacer[3], 3,0, 1, 1);

            // gl_layaout[3]->addLayout(gl_layaout[0], 0,0);
            // gl_layaout[3]->addLayout(gl_layaout[1], 1,0);
            // gl_layaout[3]->addLayout(gl_layaout[2], 2,0);

            /home/dima/dima_project/dialog_okno_qmake/dialogokno.cpp:61: ошибка: no matching function for call to ‘QGridLayout::addWidget(QSpacerItem*&, int, int, int, int)’
                 gl_layaout[3]->addWidget(si_spacer[0], 0, 1, 1, 1);
                                                                  ^
            
            /home/dima/dima_project/dialog_okno_qmake/dialogokno.cpp:64: ошибка: no matching function for call to ‘QGridLayout::addWidget(QSpacerItem*&, int, int, int, int)’
                 gl_layaout[3]->addWidget(si_spacer[1], 0,3, 1, 1);
                                                                 ^
            /home/dima/dima_project/dialog_okno_qmake/dialogokno.cpp:66: ошибка: no matching function for call to ‘QGridLayout::addWidget(QSpacerItem*&, int, int, int, int)’
                 gl_layaout[3]->addWidget(si_spacer[2], 1,0, 1, 1);
                                                                 ^
            
            /home/dima/dima_project/dialog_okno_qmake/dialogokno.cpp:69: ошибка: no matching function for call to ‘QGridLayout::addWidget(QSpacerItem*&, int, int, int, int)’
                 gl_layaout[3]->addWidget(si_spacer[3], 3,0, 1, 1);
                                                                 ^
            1 Reply Last reply
            0
            • M Offline
              M Offline
              mpergand
              wrote on 26 Nov 2021, 15:55 last edited by
              #6
              DialogOkno::DialogOkno(QWidget *parent)
                  : QWidget(parent)
              {
              
                  // starting with a vertical layout
                  auto vLayout=new QVBoxLayout;
                  setLayout(vLayout);
                  
                  // add first horiontal layout for bloc 1 & 2
                  auto hLayout1=new QHBoxLayout;
                  vLayout->addLayout(hLayout1);
                  
                  // first bloc
                  // vertical layout for first bloc
                  auto vLayout1=new QVBoxLayout;
                  vLayout1->setContentsMargins(0,0,10,0);
                  hLayout1->addLayout(vLayout1);
                  // add label and line edit
                  auto label=new QLabel("hla_global");
                  vLayout1->addWidget(label);
                  auto edit=new QLineEdit("server_ip_global");
                  vLayout1->addWidget(edit);
                  edit=new QLineEdit("server_port_global");
                  vLayout1->addWidget(edit);
                  
                  // second bloc
                  auto vLayout2=new QVBoxLayout;
                  hLayout1->addLayout(vLayout2);
                  // add label and line edit
                  label=new QLabel("hla_local");
                  vLayout2->addWidget(label);
                  edit=new QLineEdit("server_ip_local");
                  vLayout2->addWidget(edit);
                  edit=new QLineEdit("server_port_local");
                  vLayout2->addWidget(edit);
                  
                  // third bloc
                  // add second horiontal layout for bloc 3
                  auto hLayout2=new QHBoxLayout;
                  hLayout2->setContentsMargins(0,10,0,0);
                  vLayout->addLayout(hLayout2);
                  auto vLayout3=new QVBoxLayout;
                  vLayout3->setContentsMargins(0,0,10,0);
                  hLayout2->addLayout(vLayout3);
                  // add label and line edit
                  label=new QLabel("loger");
                  vLayout3->addWidget(label);
                  edit=new QLineEdit("log_period");
                  vLayout3->addWidget(edit);
                  edit=new QLineEdit("log_time");
                  vLayout3->addWidget(edit);
                  
                  hLayout2->addStretch(0);    // push items left
                  
                  
                  vLayout->addStretch(0); // push items up
              }
              

              alt text

              1 Reply Last reply
              1
              • T Offline
                T Offline
                timob256
                wrote on 26 Nov 2021, 15:59 last edited by timob256
                #7

                i mace this :)

                #include "dialogokno.h"
                
                DialogOkno::DialogOkno(QWidget *parent)
                    : QWidget(parent)
                {
                    // обявл элементы
                    gl_layaout[0] = new QGridLayout(parent);
                    gl_layaout[1] = new QGridLayout(parent);
                    gl_layaout[2] = new QGridLayout(parent);
                
                    gl_layaout[3] = new QGridLayout(parent);
                
                
                    l_label[0] = new QLabel(parent);
                    l_label[1] = new QLabel(parent);
                    l_label[2] = new QLabel(parent);
                
                    le_edit[0] = new QLineEdit(parent);
                    le_edit[1] = new QLineEdit(parent);
                    le_edit[2] = new QLineEdit(parent);
                    le_edit[3] = new QLineEdit(parent);
                    le_edit[4] = new QLineEdit(parent);
                    le_edit[5] = new QLineEdit(parent);
                    le_edit[6] = new QLineEdit(parent);
                
                    // настройки элеметов (стилизация)
                
                    // заполнение элементов
                    l_label[0]->setText("hla_global");
                    l_label[1]->setText("hla_local");
                    l_label[2]->setText("logger");
                
                    le_edit[0]->setText("server_ip_global");
                    le_edit[1]->setText("server_port_global");
                
                    le_edit[2]->setText("server_port_local");
                    le_edit[3]->setText("server_port_local");
                
                    le_edit[4]->setText("log");
                    le_edit[5]->setText("log_period_ms");
                    le_edit[6]->setText("log_size_in_mb");
                
                    //разложение элементов по группам
                
                    gl_layaout[0]->addWidget(l_label[0], 0, 0, 1, 1);
                    gl_layaout[0]->addWidget(le_edit[0], 1, 0, 1, 1);
                    gl_layaout[0]->addWidget(le_edit[1], 2, 0, 1, 1);
                
                    gl_layaout[1]->addWidget(l_label[1], 0, 0, 1, 1);
                    gl_layaout[1]->addWidget(le_edit[2], 1, 0, 1, 1);
                    gl_layaout[1]->addWidget(le_edit[3], 2, 0, 1, 1);
                
                    gl_layaout[2]->addWidget(l_label[2], 0, 0, 1, 1);
                    gl_layaout[2]->addWidget(le_edit[4], 1, 0, 1, 1);
                    gl_layaout[2]->addWidget(le_edit[5], 2, 0, 1, 1);
                    gl_layaout[2]->addWidget(le_edit[6], 3, 0, 1, 1);
                
                
                    gl_layaout[3]->addLayout(gl_layaout[0], 0,0);
                
                    si_spacer[0] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
                 
                    gl_layaout[3]->addItem(si_spacer[0],0,1);
                
                    gl_layaout[3]->addLayout(gl_layaout[1], 0,2);
                    si_spacer[1] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
                 
                    gl_layaout[3]->addItem(si_spacer[1], 0, 3);
                    si_spacer[2] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding);
                 
                    gl_layaout[3]->addItem(si_spacer[2],1,0);
                    gl_layaout[3]->addLayout(gl_layaout[2], 2,0);
                    si_spacer[3] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding);
                 
                    gl_layaout[3]->addItem(si_spacer[3],3,0);
                
                 
                
                
                    this->setLayout(gl_layaout[3]);
                }
                
                DialogOkno::~DialogOkno()
                {
                
                }
                

                Screenshot_20211126_185726.png

                1 Reply Last reply
                0

                5/7

                26 Nov 2021, 14:46

                • Login

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