Quad Splitter Implementation in QT
-
I want to implement Quad splitter in QT. Which means I have 2 horizontal splitter and 1 vertical splitter. And when I click at the center, I should be able to move handle in both horizontal and vertical direction.
I referred to few following posts:
and I am trying to implement in the similar fashion.
I created custom splitter as follows:
custom_splitter.h
#ifndef CUSTOM_SPLITTER_H #define CUSTOM_SPLITTER_H #include <QSplitter> class CustomSplitter : public QSplitter { Q_OBJECT public: CustomSplitter(QWidget *parent = nullptr); public: void MoveSplitter(int position, int index); }; #endif // CUSTOM_SPLITTER_H custom_splitter.cpp #include "custom_splitter.h" CustomSplitter::CustomSplitter(QWidget *parent) : QSplitter(parent) { } void CustomSplitter::MoveSplitter(int position, int index) { this->moveSplitter(position, index); }
and in QT designed promoted all 3 qsplitters to this custom splitter.
And then in main.cpp
connect(ui->splitter_v, &CustomSplitter::splitterMoved, ui->splitter_h1, &CustomSplitter::MoveSplitter);
However, I get error
error: C2664: 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const': cannot convert argument 3 from 'QSplitter *' to 'const CustomSplitter *'
Please help in solving this issue
-
Hi,
AFAICT, you have a QSplitter in your ui object however you are using your custom class to pass signal information.
-
-
@magicstar can you show your .ui file?
-
@aha_1980
Yes. The problem was somewhere in ui file. Rebuilding solved the error.
However, I am not yet able to achieve Quad splitter.How do I get horizontal position of QSplitter handle which has vertical orientation ? SplitterMoved signal only gives vertical position.
-
@magicstar said in Quad Splitter Implementation in QT:
How do I get horizontal position of QSplitter handle which has vertical orientation ?
AFAIK you cannot. A vertical splitter does not have horizontal position.
Here is one possible solution :
customsplitter.h#ifndef CUSTOMSPLITTER_H #define CUSTOMSPLITTER_H #include <QSplitter> class CustomSplitter : public QSplitter { Q_OBJECT public: CustomSplitter(QWidget *parent = nullptr); void bind(CustomSplitter *splitter); private slots: void onBoundSplitterMoved(int pos, int index); private: int lastPos = -1; int lastIndex = -1; }; #endif // CUSTOMSPLITTER_H
customesplitter.cpp
#include "customsplitter.h" #include <QTimer> CustomSplitter::CustomSplitter(QWidget *parent) : QSplitter(parent) { } void CustomSplitter::bind(CustomSplitter *splitter) { connect(splitter, &QSplitter::splitterMoved, this, &CustomSplitter::onBoundSplitterMoved); } void CustomSplitter::onBoundSplitterMoved(int pos, int index) { if(pos == lastPos && index == lastIndex) return; lastPos = pos; lastIndex = index; moveSplitter(pos, index); }
widget.cpp
Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget) { ui->setupUi(this); ui->splitHB->bind(ui->splitHT); //Bind Horizontal Bottom to Horizontal Top ui->splitHT->bind(ui->splitHB); //Bind Horizontal Top with Horizontal Bottom }
@magicstar said in Quad Splitter Implementation in QT:
And when I click at the center, I should be able to move handle in both horizontal and vertical direction
I think this is not possible except if you implement your own splitter.
6/7