How to conditionally drag a QSplitter handle
-
Hi I have a four way Pane graphic viewport, and each pain has an action for maximize it and minimize it.
When I maximize the splitter, they have a bool that indicate whet that viewport is minimize or not.It all work very well with the exception that QT allows to drag the splitter handler even when they are all collapsed,
Basically I want to trap the even that move the splitter handle and reject test if any of the tow children is maximized, if it is the even should be consume as do nothingI see the splitter class has these four special events, but nine of them is called when dragging the handle.
@virtual void changeEvent ( QEvent * ev )
virtual void childEvent ( QChildEvent * c )
virtual bool event ( QEvent * e )
virtual void resizeEvent ( QResizeEvent * )@Can someone please tell me how to intersect, the Dragging handle event before it do the operation?
-
Subclass the QSplitter to your own. You can find the possible virtual eventhadlers in "qt/src/gui/widgets/qsplitter.h"
@class YourOwn : public QSplitter {
Q_OBJECT;
public:
YourOwn(QWidget* parent = NULL);
protected:
virtual void mouseMoveEvent(QMouseEvent *);
virtual void mousePressEvent(QMouseEvent *);
virtual void mouseReleaseEvent(QMouseEvent *);
virtual void resizeEvent(QResizeEvent *);
};void YourOwn::mouseMoveEvent(QMouseEvent *ev) {
<do what you want> //To make the mouse move effective, you may call original handler
QSplitter::mouseMoveEvent(ev);
}
@
If subclass is ready, change your QSplitter object on the from to YourOwn class with the "Promote" command (UI -right mouse click - Promote..)I hope this helps. It took some days for me to see this clearly... thanks redirected to "peppe" and "ivan.todorovich":))
-
well I just added this
@class alchemediaCanvas: public QSplitter
{
public:
alchemediaCanvas(QWidget* const parent);
~alchemediaCanvas(void);void mouseMoveEvent(QMouseEvent *ev)
{
QSplitter::mouseMoveEvent(ev);
}alchemediaVerticalSpliter* m_leftPane;
alchemediaVerticalSpliter* m_rightPane;
QByteArray m_maximizedState;
};@But that does not really does it.
I set a break point on the function, and it hit the break point if I click on the toolbar, but not when I click on the handle, I need it when I click the handle.there has to be a way to do this, bu I cannot figure it out.
-
Oh I see, your suggestion showed me how to do it.
There is a method called createHandle,
So instead of overwriting mouseMoveEvent on the spliter I oveloaded createHandle to create my own QSplitterHandle and on the class I overload
mouseMoveEvent, and it worked like a cham
here are the classes, in case you wonder
@class alchemediaCanvas: public QSplitter
{
public:
alchemediaCanvas(QWidget* const parent);
~alchemediaCanvas(void);QSplitterHandle *createHandle()
{
return new alchemediaSplietHandle (Qt::Horizontal, this);
}}
class alchemediaSplietHandle: public QSplitterHandle
{
public:
alchemediaSplietHandle(Qt::Orientation o, QSplitter *parent)
:QSplitterHandle (o, parent)
{}
void mouseMoveEvent(QMouseEvent *ev)
{
// do my conditional move here.
}
};@