Skip to content

Instantly share code, notes, and snippets.

@Madsy
Created September 30, 2009 11:10
Show Gist options
  • Save Madsy/198006 to your computer and use it in GitHub Desktop.
Save Madsy/198006 to your computer and use it in GitHub Desktop.
#include <QtGui/QApplication>
#include <QSplitter>
#include <QPushButton>
class QCustomSplitter : public QSplitter
{
Q_OBJECT
public:
QCustomSplitter(QWidget* parent = 0);
QCustomSplitter(Qt::Orientation orient, QWidget* parent = 0);
void SetSibling(QCustomSplitter* sibling);
public slots:
void signalMoveSplitter(int posi, int index);
protected:
QCustomSplitter* sibl;
int pos;
};
class QSplitterFourWay : public QObject
{
public:
QSplitterFourWay(QWidget* Parent = 0);
QSplitter* mainSplitter();
QSplitter* leftSplitter();
QSplitter* rightSplitter();
QSplitter *splitter;
QCustomSplitter *left, *right;
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
QSplitterFourWay s;
};
QCustomSplitter::QCustomSplitter(QWidget* parent) : QSplitter(parent), pos(0){}
QCustomSplitter::QCustomSplitter(Qt::Orientation orient, QWidget* parent) : QSplitter(orient, parent), pos(0){}
void QCustomSplitter::SetSibling(QCustomSplitter* sibling){sibl = sibling;}
void QCustomSplitter::signalMoveSplitter(int posi, int index)
{
if(this->pos == posi)
return;
Q_ASSERT(index == 1);
this->pos = posi;
moveSplitter(posi, index);
return;
}
QSplitterFourWay::QSplitterFourWay(QWidget* parent) :
splitter( new QSplitter(Qt::Horizontal, parent) ),
left( new QCustomSplitter(Qt::Vertical, splitter) ),
right( new QCustomSplitter(Qt::Vertical, splitter) )
{
left->SetSibling(right);
right->SetSibling(left);
splitter->addWidget(left);
splitter->addWidget(right);
connect(left, SIGNAL(splitterMoved(int, int)), right, SLOT(signalMoveSplitter(int, int)));
connect(right, SIGNAL(splitterMoved(int, int)), left, SLOT(signalMoveSplitter(int, int)));
}
QSplitter* QSplitterFourWay::mainSplitter(){ return splitter; }
QSplitter* QSplitterFourWay::leftSplitter(){ return left; }
QSplitter* QSplitterFourWay::rightSplitter(){ return right; }
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), s(NULL)
{
s = new QSplitterFourWay(this);
QSplitter* top = s->mainSplitter();
QSplitter* left = s->leftSplitter();
QSplitter* right = s->rightSplitter();
left->addWidget(new QPushButton("button1") );
left->addWidget(new QPushButton("button2") );
right->addWidget(new QPushButton("button3") );
right->addWidget(new QPushButton("button4") );
top->setMinimumSize(640, 480);
top->setMaximumSize(800, 600);
this->setMinimumSize(640, 480);
}
MainWindow::~MainWindow()
{
if(s)
delete s;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment