QT splitters

Why when I run this code, it runs correctly but the two push buttons don't have
a splitter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <QApplication>
#include <QSplitter>
#include <QPushButton>
#include <QHBoxLayout>
#include <QTextEdit>

int main(int argc, char *argv[]){

    QApplication prog(argc, argv);

    QWidget *mainWindow = new QWidget();

    QSplitter *splitter = new QSplitter();

    QPushButton *one = new QPushButton("one");
    QPushButton *two = new QPushButton("two");

    splitter->addWidget(one);
    splitter->addWidget(two);

    QHBoxLayout *layout = new QHBoxLayout();

    layout->addWidget(one);
    layout->addWidget(two);

    mainWindow->setLayout(layout);

    mainWindow->show();


    return prog.exec(); // re loops the program; a little like a while loop
}
Last edited on
I haven't used splitters myself, so I might be way off here, but shouldn't you add the splitter to your layouts rather than adding the buttons?

It looks like it inherits somewhere down the line from the QWidget class so it should be included using the addWidget function...
Last edited on
That actually worked thank you sir.
Topic archived. No new replies allowed.