Qt/C++ - Lesson 010. QSplitter – how to add splitter?

QPallete, QSplitter, QSplitter color, QSplitter example, Qt

Qualitative layout always increases application usability, and this is true for all kinds of applications, from desktop to mobile. One such interface elements, which can improve usability is QSplitter class, which is an object-type layout with a movable divider that separates the two areas in the application interface.

Project Structure for QSplitter

Project Structure for QSplitter

Project structure completely unremarkable and a little interesting, since the main actions will be carried out in the designer, and QSplitter in mainwindow.cpp setting will produce a minimum.

Step by step with QSplitter

The first step - First add the two types of layout objects, which will be located elements of the interface

Adiing two layouts

The second step - Choose a layout, both holding the Ctrl key and click on the button "Lay horizontally delimited", well, or "Lay vertically delimited", who despite what you need.

layout with QSplitter

The third step - Stretch the area in which is located our QSplitter. This is necessary if the appearance of your QSplitter behaved not as you would have liked. To do this, select the parent widget, which is your QSplitter and click on the button "Lay on the grid." As a result, we obtain a result similar to the figure below.

Stretch the area with QSplitter

The fourth step - we distribute multiple objects for clarity.

The fifth step - Correct the code to adjust the tension areas when you run the application and set the color separator.

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    /* We set the parameters of areas stretching. 
     * Areas considered from left to right. 
     * The method setStretchFactor first set index field, and then her weight. 
     * Thus the first region set maximum weight and the second region is minimal.
     * */
    ui->splitter->setStretchFactor(0,1);
    ui->splitter->setStretchFactor(1,0);

    /* Also, just I want to show you how to choose the color separator. 
     * To do this we need to use a class QPallete, for which you choose the background color.
     * */
    QPalette p;
    p.setColor(QPalette::Background, Qt::red);
    /* And sets the palette QSplitter
     * */
    ui->splitter->setPalette(p);
}

MainWindow::~MainWindow()
{
    delete ui;
}

Result

10% refund of hotel reservation amount on Booking
10% refund of hotel reservation amount on Booking
We offer a link with a 10% return on the amount of the order when booking a hotel through Booking
Support the author Donate

Comments

Only authorized users can post comments.
Please, Log in or Sign up
D
Aug. 16, 2019, 12:58 p.m.
Damir

C++ - Тест 003. Условия и циклы

  • Result:92points,
  • Rating points8
D
Aug. 16, 2019, 12:46 p.m.
Damir

C++ - Test 005. Structures and Classes

  • Result:75points,
  • Rating points2
u
Aug. 14, 2019, 2:55 p.m.
unrealproro

C++ - Test 005. Structures and Classes

  • Result:83points,
  • Rating points4
Last comments
D
Aug. 17, 2019, 9:04 a.m.
Damir

github ChekableTView Правой групповая смена значения при перетаскивании левой как обычно.
Aug. 16, 2019, 1:03 p.m.
Evgenij Legotskoj

Потому, что в минуте 60 секунд
Aug. 16, 2019, 12:16 p.m.
Dmitrij

а почему делитель 60000, а не 1000?
g
Aug. 14, 2019, 1:27 a.m.
grig_p

Спасибо большое. Получилось
Aug. 13, 2019, 10:43 a.m.
Evgenij Legotskoj

Самая главная проблема в том, что у вас это константные переменные, и инициализируется они один единственный раз при запуске программы. Поэтому делать динамический перевод в таком случае у …
Now discuss on the forum
Aug. 18, 2019, 3:22 a.m.
Ruslan Polupan

Т.е. таблицы в БД к которым обращается приложение могут отсутсвовать?
Aug. 15, 2019, 3:19 a.m.
Mihailll

Плюсы и qml отличаются, с++ логичней
Aug. 14, 2019, 8:20 a.m.
Evgenij Legotskoj

Да это не столько баги QML, сколько поведение JavaScript, который используется в нём. Из-за отсутствия строгой типизации получаем некоторые проблемы с преобразованием типов. в итоге, на первый в…
Aug. 14, 2019, 2:33 a.m.
BlinCT

Ошибка найдена) недосмотрел.
Aug. 13, 2019, 3:52 a.m.
Evgenij Legotskoj

Бери остаток от деления #include <QCoreApplication>#include <QTime>#include <QDebug>int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); QTime time…
Looking for a Job?
14,000.00 руб. - 40,000.00 руб.
Разработчик Qt
Annino, Moscow Oblast, Russia
5,000.00 руб. - 15,000.00 руб.
Дизайнер
Moskovskiy, Moscow, Russia
25,000.00 руб. - 30,000.00 руб.
Разработчик Qt/C++
Barnaul, Altai Krai, Russia

For registered users on the site there is a minimum amount of advertising

EVILEG
About
Services
Join us
© EVILEG 2015-2019
Recommend hosting TIMEWEB