Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit a2aefc5

Browse files
author
mttwc
committed
Demonstrates splitters
1 parent b68ab0f commit a2aefc5

File tree

6 files changed

+48
-99
lines changed

6 files changed

+48
-99
lines changed

HelloQt.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
QT += widgets
77

88
SOURCES = src/main.cpp \
9-
src/progress_bar_demonstration.cpp \
9+
src/splitter_demonstration.cpp \
1010

11-
HEADERS = src/progress_bar_demonstration.h
11+
HEADERS = src/splitter_demonstration.h
1212

1313
CONFIG -= app_bundle
1414
CONFIG += c++11

src/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#include <QApplication>
22
#include <QWidget>
3-
#include "progress_bar_demonstration.h"
3+
#include "splitter_demonstration.h"
44

55
int main(int argc, char *argv[])
66
{
77
QApplication app(argc, argv);
88

9-
ProgressBarDemonstration window;
9+
SplitterDemonstration window;
1010

11-
window.resize(250, 150);
12-
window.setWindowTitle("Progress Bar Demonstration");
11+
window.resize(350, 300);
12+
window.setWindowTitle("Splitter Demonstration");
1313
window.show();
1414

1515
return app.exec();

src/progress_bar_demonstration.cpp

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/progress_bar_demonstration.h

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/splitter_demonstration.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "splitter_demonstration.h"
2+
#include <QFrame>
3+
#include <QSplitter>
4+
#include <QHBoxLayout>
5+
6+
SplitterDemonstration::SplitterDemonstration(QWidget *parent)
7+
: QWidget(parent)
8+
{
9+
QHBoxLayout *hbox = new QHBoxLayout(this);
10+
11+
QFrame *topLeft = new QFrame(this);
12+
topLeft->setFrameShape(QFrame::StyledPanel);
13+
14+
QFrame *topRight = new QFrame(this);
15+
topRight->setFrameShape(QFrame::StyledPanel);
16+
17+
QSplitter *splitter1 = new QSplitter(Qt::Horizontal, this);
18+
splitter1->addWidget(topLeft);
19+
splitter1->addWidget(topRight);
20+
21+
QFrame *bottom = new QFrame(this);
22+
bottom->setFrameShape(QFrame::StyledPanel);
23+
24+
QSplitter *splitter2 = new QSplitter(Qt::Vertical, this);
25+
splitter2->addWidget(splitter1);
26+
splitter2->addWidget(bottom);
27+
28+
// The first 'row' will be 50 pixels wide in the vertical direction, the second 'row' will be 100
29+
QList<int> sizes({50, 100});
30+
splitter2->setSizes(sizes);
31+
32+
hbox->addWidget(splitter2);
33+
}

src/splitter_demonstration.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
#include <QWidget>
4+
5+
class SplitterDemonstration : public QWidget
6+
{
7+
public:
8+
SplitterDemonstration(QWidget *parent = 0);
9+
};

0 commit comments

Comments
 (0)