Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Restrict hidding of qsplitterhandle in qsplitter

    General and Desktop
    2
    8
    785
    Loading More Posts
    • 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.
    • N
      NoumanYosuf last edited by NoumanYosuf

      Hello all,

      PROBLEM STATMENT :
      I wanted to give clickable feature to QSplitterHandle of QSplitter. as I wanted to perform show or hide some of the widgets in QSplitter.
      Something like the button between pdf and bookmark in pdf readers, which is drag-able ( to incress/decrees widget size ratio) and clickable too( to show/hide bookmarks) in the below screenshot.0_1554476234460_0c82bc8a-4b35-43b3-8c30-e53652b229d6-image.png.

      I have extended the QSplitterHandle to add a signal which is emited when handle is clicked (mouseReleaseEvent()). and also extended qsplitter to use above QSplitterHandle in the createHandle() of qsplitter.
      Below is the sample code of the same:

      class MySplitterHandle : public QSplitterHandle
      {
      public:
          explicit MySplitterHandle(Qt::Orientation o, QSplitter *parent);
          void mouseReleaseEvent(QMouseEvent *) override;
      signal:
      void clicked();
      };
      
      class MySplitter : public QSplitter
      {
      public:
          explicit MySplitter(QWidget* parent = nullptr);
      protected:
           QSplitterHandle *createHandle()
        {
           return new MySplitterHandle(this->orientation(),this);
        }
      };
      

      I added 2 widgets to MySplitter and made MySplitterHandle widget as 15.and I have connected the emit signal of the QSplitterHandle to a slot which hide/show (toggle) the first widget.
      Now my GUI is something like first widget, then 15 pxl QSplitterHandle and then second widget.

      ISSUE:
      when I try to hide the first widget, QSplitterHandle also get hidden along with first widget. And I am not able to get it back.
      How can I restrict QSplitterHandle to hide when hiding the first widget.

      I have tried my best to give all details so that you all can understand the issue well and guide me. Any initiative is appreciated.

      1 Reply Last reply Reply Quote 0
      • N
        NoumanYosuf last edited by NoumanYosuf

        Something like this :

        QList<int> savedSize;
        MySplitterHandle *splitterHandle=qobject_cast<MySplitterHandle*>(splitter.handle(1));
            connect(splitterHandle,SIGNAL(Clicked()),this,SLOT(handleClickedSot()));
        
        void handleClickedSot() //slot
        {
            QTimer::singleShot(50,this, &Widget2::showHideWidget);
        }
        
        void Widget2::showHideWidget()
        {
            m_ShowHideFlag=!m_ShowHideFlag;
            if(m_ShowHideFlag)
            {
                savedSize=splitter.sizes();
                QList<int> newSize(savedSize);
                newSize[0]=0; //hide first widget
                splitter.setSizes(newSize);
            }
            else
            {
                splitter.setSizes(savedSize);
            }
        }
        
        1 Reply Last reply Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi,

          Do you mean like if you would have use QSplitter::setCollapsible on that widget ?

          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 Reply Quote 0
          • N
            NoumanYosuf last edited by NoumanYosuf

            Yes I tried using setCollapsible false also but this also did not helped.
            In that case also when I try to hide the first widget, qsplitterhandle next to it also gets hidden. That's strange to me.

            1 Reply Last reply Reply Quote 0
            • N
              NoumanYosuf last edited by NoumanYosuf

              This may be out of context of this issue but I found something stranger.
              I was playing around with qsplitter and setOpaqueResize as false with a intention that resized event should not get called for added widgets in qsplitter. When I click on the handle ( without moving the handle), mouse click event is emitted and splitterMoved() signal is also emitted (even though handle is not moved).

              But on the contrary, when I set setOpaqueResize as true , on click of the handle without moving it, only mouse click event is triggered.

              This is very surprising to me. I am using qt5.12.

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                It's indeed a bit surprising but there might be some filtering done on the mouse with regard to that.

                As for my question, I think I miswrote it. From your description, it seems that you are re-implementing collapsible widgets but I may have misunderstood you. Is that the case ?

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

                N 1 Reply Last reply Reply Quote 0
                • N
                  NoumanYosuf @SGaist last edited by

                  @SGaist
                  I am not trying to re-implement collapsible widgets.My intention is to use the custum qsplitterhandle hence I have overridden the 'QSplitterHandle *createHandle()' of qsplitter baseclass.

                  1 Reply Last reply Reply Quote 0
                  • N
                    NoumanYosuf last edited by NoumanYosuf

                    I used setSizes() to hide my first widget in my onSplitterHandleClicked slot. And in that slot I am also saving the splitter sizes to restore back widgets sizes when the handle is clicked again. This works fine now.

                    1 Reply Last reply Reply Quote 0
                    • N
                      NoumanYosuf last edited by NoumanYosuf

                      Something like this :

                      QList<int> savedSize;
                      MySplitterHandle *splitterHandle=qobject_cast<MySplitterHandle*>(splitter.handle(1));
                          connect(splitterHandle,SIGNAL(Clicked()),this,SLOT(handleClickedSot()));
                      
                      void handleClickedSot() //slot
                      {
                          QTimer::singleShot(50,this, &Widget2::showHideWidget);
                      }
                      
                      void Widget2::showHideWidget()
                      {
                          m_ShowHideFlag=!m_ShowHideFlag;
                          if(m_ShowHideFlag)
                          {
                              savedSize=splitter.sizes();
                              QList<int> newSize(savedSize);
                              newSize[0]=0; //hide first widget
                              splitter.setSizes(newSize);
                          }
                          else
                          {
                              splitter.setSizes(savedSize);
                          }
                      }
                      
                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post