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. Quad Splitter Implementation in QT

Quad Splitter Implementation in QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 900 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.
  • M Offline
    M Offline
    magicstar
    wrote on 4 Oct 2019, 06:58 last edited by
    #1

    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:

    • https://forum.qt.io/topic/7144/quad-splitter-windows-an-implementation

    • https://stackoverflow.com/questions/12409647/pyqt-qsplitter-is-there-a-way-to-define-orientation-as-both-vertical-and-horizo

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 4 Oct 2019, 18:44 last edited by
      #2

      Hi,

      AFAICT, you have a QSplitter in your ui object however you are using your custom class to pass signal information.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 4 Oct 2019, 19:07 last edited by mrjj 10 Apr 2019, 19:08
        #3

        Hi
        Just right click the splitters (one by one) in Designer and choose Promote
        and then type CustomSplitter in classname.
        Then press Add button and then Promote button.
        Its now the correct type and the connect will work

        alt text

        yes, its not in a quad. just fast test :)

        1 Reply Last reply
        3
        • M Offline
          M Offline
          magicstar
          wrote on 7 Oct 2019, 04:02 last edited by
          #4

          @SGaist
          I have already promoted QSplitter to CustomSplitter through qt designer. I am still facing the issue

          A 1 Reply Last reply 7 Oct 2019, 04:09
          0
          • M magicstar
            7 Oct 2019, 04:02

            @SGaist
            I have already promoted QSplitter to CustomSplitter through qt designer. I am still facing the issue

            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 7 Oct 2019, 04:09 last edited by
            #5

            @magicstar can you show your .ui file?

            Qt has to stay free or it will die.

            M 1 Reply Last reply 7 Oct 2019, 13:28
            0
            • A aha_1980
              7 Oct 2019, 04:09

              @magicstar can you show your .ui file?

              M Offline
              M Offline
              magicstar
              wrote on 7 Oct 2019, 13:28 last edited by
              #6

              @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.

              G 1 Reply Last reply 7 Oct 2019, 13:42
              0
              • M magicstar
                7 Oct 2019, 13:28

                @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.

                G Offline
                G Offline
                Gojir4
                wrote on 7 Oct 2019, 13:42 last edited by
                #7

                @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.

                1 Reply Last reply
                3

                6/7

                7 Oct 2019, 13:28

                • Login

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