Different behaviors code compiled against Qt5 and Qt4



  • Hi all,

    I'm testing a simple code and can't figure out a different behavior between compiled against Qt5 and Qt4. The top handle can't be moved except when other handles are moved first (a catch and miss). This happens in Qt4, but never occurred when it's compiled against Qt5 (it behaves properly in Qt5).

    Here's the code;

    test.h
    @
    #include <qmainwindow.h>
    #include <qsplitter.h>
    #include <qtextedit.h>

    class QCloseEvent;

    class CustomSplitter : public QSplitter
    {

    public:
    CustomSplitter(QWidget * parent);
    void adjustPosition(int p);

    protected:
    void paintEvent ( QPaintEvent * pe );
    };

    class mainWindow : public QMainWindow
    {
    public:
    mainWindow(QWidget * parent);
    void synchronize(QObject * sender);

    protected:
    void closeEvent( QCloseEvent* );

    public:
    CustomSplitter * splitter1;
    CustomSplitter * splitter2;
    QTextEdit * a;
    QTextEdit * b;
    QTextEdit * c;
    QTextEdit * d;
    };
    @

    test.cpp
    @
    #include <QCloseEvent>
    #include "test.h"

    mainWindow::mainWindow(QWidget * parent) : QMainWindow( parent )
    {
    QSplitter * mainSplitter = new QSplitter(this);
    mainSplitter->setOrientation(Qt::Vertical);
    mainSplitter->setFrameShadow(QFrame::Sunken);

    splitter1 = new CustomSplitter(mainSplitter);
    a = new QTextEdit(splitter1);
    b = new QTextEdit(splitter1);

    splitter2 = new CustomSplitter(mainSplitter);
    c = new QTextEdit(splitter2);
    d = new QTextEdit(splitter2);

    setCentralWidget(mainSplitter);

    }

    void mainWindow::synchronize(QObject * sender)
    {
    if(splitter1->sizes()==splitter2->sizes())
    return;

    CustomSplitter* s = (CustomSplitter*)sender;
    if (s==splitter1) {
    splitter2->adjustPosition(splitter1->sizes()[0]);
    }
    else if(s==splitter2) {
    splitter1->adjustPosition(splitter2->sizes()[0]);
    };

    }

    void mainWindow::closeEvent( QCloseEvent* ce )
    {
    ce->accept();
    //return;
    }

    CustomSplitter::CustomSplitter(QWidget * parent) : QSplitter( parent )
    {

    setFrameShadow(QFrame::Sunken);
    setLineWidth(1);
    setMidLineWidth(1);
    setHandleWidth(1);
    

    }

    void CustomSplitter::paintEvent (QPaintEvent )
    {
    ((mainWindow
    )parent()->parent())->synchronize(this);
    }

    void CustomSplitter::adjustPosition(int p)
    {
    moveSplitter(p,1);
    refresh();
    }
    @

    Any ideas why that happens?

    TIA.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.