Evgenii Legotckoi
Evgenii LegotckoiAug. 26, 2015, 9:15 a.m.

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

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

We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

Comments

Only authorized users can post comments.
Please, Log in or Sign up
ОК

Qt - Test 001. Signals and slots

  • Result:47points,
  • Rating points-6
A
  • Alena
  • Jan. 19, 2025, 7:41 p.m.

C++ - Test 005. Structures and Classes

  • Result:58points,
  • Rating points-2
OI

C++ - Test 001. The first program and data types

  • Result:40points,
  • Rating points-8
Last comments
ИМ
Игорь МаксимовNov. 22, 2024, 7:51 p.m.
Django - Tutorial 017. Customize the login page to Django Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
Evgenii Legotckoi
Evgenii LegotckoiOct. 31, 2024, 9:37 p.m.
Django - Lesson 064. How to write a Python Markdown extension Добрый день. Да, можно. Либо через такие же плагины, либо с постобработкой через python библиотеку Beautiful Soup
A
ALO1ZEOct. 19, 2024, 3:19 p.m.
Fb3 file reader on Qt Creator Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html
ИМ
Игорь МаксимовOct. 5, 2024, 2:51 p.m.
Django - Lesson 064. How to write a Python Markdown extension Приветствую Евгений! У меня вопрос. Можно ли вставлять свои классы в разметку редактора markdown? Допустим имея стандартную разметку: <ul> <li></li> <li></l…
d
dblas5July 5, 2024, 6:02 p.m.
QML - Lesson 016. SQLite database and the working with it in QML Qt Здравствуйте, возникает такая проблема (я новичок): ApplicationWindow неизвестный элемент. (М300) для TextField и Button аналогично. Могу предположить, что из-за более новой верси…
Now discuss on the forum
n
nklyJan. 3, 2025, 10:52 a.m.
Нужно запретить перемещение только некоторых итемов, остальные перемещать можно. Вопрос решен. Узнать QModelIndex элемента на который мы перетаскиваем другой элемент, можно с помощью функции indexAt(event->position().toPoint()) представления QTreeViev вызываемой в переопр…
AW
Ayden WatkinsJan. 2, 2025, 8:09 a.m.
Why Paying for a Research Paper Can Be a Smart Choice Writing a research paper can be a daunting task, especially when faced with tight deadlines, complex topics, or a lack of resources. For many students, paying for a research paper is a practical…
p
pimacontrols85Dec. 31, 2024, 5:39 p.m.
Finding the Right Rittal Small Enclosure for Your Needs Rittal is a leading manufacturer of enclosures for industrial and IT applications. Their small enclosures offer a compact and reliable solution for a wide range of needs, from housing electronic…
Donald Randolph
Donald RandolphDec. 30, 2024, 10:59 a.m.
Personal Injury lawyer Santa Monica As an experienced Santa Monica personal injury lawyer, Donald C. Randolph has recovered over $100 Million in verdicts and settlements for our clients. In severe injury cases, this compensation i…
Nirvana Yoga School
Nirvana Yoga SchoolDec. 30, 2024, 1:13 p.m.
OAuth2.0 через VK, получение email Nirvana Yoga School is one of the most trusted and reputed traditional Rishikesh yoga courses , India certified by Yoga Alliance, USA. We aim to spread traditional yoga teachings so t…

Follow us in social networks