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. Translate instructions QT Creator in C ++
Forum Updated to NodeBB v4.3 + New Features

Translate instructions QT Creator in C ++

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.5k Views 2 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.
  • B Offline
    B Offline
    bvox
    wrote on last edited by
    #1

    Good morning.
    I do not understand how to write instructions for Qt 5.4 in C ++ if I take as an example the following instructions generated by Qt Creator. Can you give me a hand? (sorry for my english)

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>prova1</class>
    <widget class="QMainWindow" name="prova1">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>prova1</string>
    </property>
    <widget class="QWidget" name="centralWidget">
    <widget class="QWidget" name="horizontalLayoutWidget">
    <property name="geometry">
    <rect>
    <x>10</x>
    <y>10</y>
    <width>160</width>
    <height>80</height>
    </rect>
    </property>
    <layout class="QHBoxLayout" name="horizontalLayout">
    <item>
    <widget class="QLineEdit" name="lineEdit_2"/>
    </item>
    <item>
    <widget class="QLineEdit" name="lineEdit_3"/>
    </item>
    <item>
    <widget class="QLineEdit" name="lineEdit"/>
    </item>
    </layout>
    </widget>
    </widget>
    <widget class="QMenuBar" name="menuBar">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>22</height>
    </rect>
    </property>
    </widget>
    </widget>
    <layoutdefault spacing="6" margin="11"/>
    <resources/>
    <connections/>
    </ui>

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Why do you want to write this code by hand? It is automatically created by Qt Designer and transformed into C++ during compilation (see the ui_*.h files in your build directory if you want to know how that C++ code looks like). It can be written manually, also in pure C++, if there is a need.

      (Z(:^

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bvox
        wrote on last edited by
        #3

        to understand how you place widgets on the form. I can not write three labels in position 1,1 - 100,30 - 300,80
        thanks.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Static UIs are usually not a good idea. Better use layouts:

          QVBoxLayout *layout = new QVBoxLayout(this);
          QLabel *label1 = new QLabel;
          QLabel *label2 = new QLabel;
          QLabel *label3 = new QLabel;
          layout->addWidget(label1);
          layout->addWidget(label2);
          layout->addWidget(label3);
          

          This will give you a more flexible and better-looking UI.

          (Z(:^

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bvox
            wrote on last edited by
            #5

            I integrated the class prova1 (prova1.cpp) generated by Qt Creator in this way:

            #include "prova1.h"
            #include "ui_prova1.h"
            #include <QVBoxLayout>
            #include <QLabel>
            #include <QLayout>
            
            prova1::prova1(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::prova1)
            {
                ui->setupUi(this);
            
                int left = 0;
                int top = 0;
                int width = 50;
                int height = 20;
            
                QHBoxLayout *hboxlabelRONE = new QHBoxLayout();
                hboxlabelRONE->setGeometry(QRect(0,0,100,30));
                left = 0;
                QLabel *LabelNE = new QLabel ("NE");
                LabelNE->setGeometry(QRect(left,top,width,height));
                left += width;
                QLabel *LabelRO = new QLabel ("RO");
                LabelRO->setGeometry(QRect(left,top,width,height));
                hboxlabelRONE->addWidget(LabelNE);
                hboxlabelRONE->addWidget(LabelRO);
            
                QHBoxLayout *hboxlabelPADI = new QHBoxLayout();
                hboxlabelPADI->setGeometry(QRect(100,0,80,30));
                left += width;
                QLabel *LabelPA = new QLabel ("PA");
                LabelPA->setGeometry(QRect(left,top,width,height));
                left += width;
                QLabel *LabelDI = new QLabel ("DI");
                LabelDI->setGeometry(QRect(left,top,width,height));
                hboxlabelPADI->addWidget(LabelPA);
                hboxlabelPADI->addWidget(LabelDI);
            
                QHBoxLayout *hboxlabelBAAL = new QHBoxLayout();
                hboxlabelBAAL->setGeometry(QRect(180,0,80,30));
                left += width;
                QLabel *LabelBA = new QLabel ("BA");
                LabelBA->setGeometry(QRect(left,top,width,height));
                left += width;
                QLabel *LabelAL = new QLabel ("AL");
                LabelAL->setGeometry(QRect(left,top,width,height));
                hboxlabelBAAL->addWidget(LabelBA);
                hboxlabelBAAL->addWidget(LabelAL);
            
                QWidget *centralWidget = this->centralWidget();
                centralWidget->setLayout(hboxlabelRONE);
                centralWidget->setLayout(hboxlabelPADI);
                centralWidget->setLayout(hboxlabelBAAL);
            
            }
            
            prova1::~prova1()
            {
                delete ui;
            }
            

            But I just get a form with the label "NE" in position around (0, 1/2 height form) and the label "RO" in position approximately (1/2 width, 1/2 height).
            The labels "PA", "DI", "BA", "AL" does not appear on the form.
            I do not know how to make them look all 6 labels on the top left. Help me? Thanks.

            1 Reply Last reply
            0

            • Login

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