Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Tips - How to sync several QSplitter

Tips - How to sync several QSplitter

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 448 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Romain CR Offline
    Romain CR Offline
    Romain C
    wrote on last edited by VRonin
    #1

    Hello everyone,
    Today I'm delivering a small tip, taht allows me to sync two horizontal QSplitter.
    So let's begin by the problem, QSplitter can emit a signal when is moved : QSplitter::splitterMoved(int, int)
    But we don't have a method that allow us to set the new position, QSplitter:moveSplitter(int,int) is protected.

    So let's write a new class and call it like you want, in my case QsplitterExt

    #ifndef QSPLITTEREXT_H
    #define QSPLITTEREXT_H
    
    #include <QSplitter>
    
    class QSplitterExt : public QSplitter
    {
        Q_OBJECT
    
    public slots:
        void moveSplitter(int pos, int index)
        {
            if( index >= sizes().size() )
            {
                return;
            }
            bool oldState = blockSignals(true);
            QSplitter::moveSplitter(pos, index);
            blockSignals(oldState);
        }
    };
    
    #endif // QSPLITTEREXT_H
    

    Now we got an external slot to receive a signal.

    Let connect splitters:

    QSplitterExt* h1Splitter = new QSplitterExt;
    QSplitterExt* h2Splitter = new QSplitterExt;
    connect(h1Splitter,SIGNAL(splitterMoved(int, int)),h2Splitter,SLOT(moveSplitter(int,int)));
    connect(h2Splitter,SIGNAL(splitterMoved(int, int)),h1Splitter,SLOT(moveSplitter(int,int)));
    

    It work like a charm!

    Best regard!
    Romain

    1 Reply Last reply
    1

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved