how to type an interface without a ui editor ??
-
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() { }
-
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);
-
@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);
^ -
/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. -
@mpergand thanks for the help :3
i traing mace this
only mace this :(
```
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); ^
-
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 }
-
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() { }