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. Restrict hidding of qsplitterhandle in qsplitter
Forum Updated to NodeBB v4.3 + New Features

Restrict hidding of qsplitterhandle in qsplitter

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 1.7k Views 2 Watching
  • 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 Offline
    N Offline
    NoumanYosuf
    wrote on last edited by NoumanYosuf
    #1

    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
    0
    • N Offline
      N Offline
      NoumanYosuf
      wrote on last edited by NoumanYosuf
      #8

      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
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        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
        0
        • N Offline
          N Offline
          NoumanYosuf
          wrote on last edited by NoumanYosuf
          #3

          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
          0
          • N Offline
            N Offline
            NoumanYosuf
            wrote on last edited by NoumanYosuf
            #4

            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
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #5

              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
              0
              • SGaistS SGaist

                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 ?

                N Offline
                N Offline
                NoumanYosuf
                wrote on last edited by
                #6

                @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
                0
                • N Offline
                  N Offline
                  NoumanYosuf
                  wrote on last edited by NoumanYosuf
                  #7

                  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
                  0
                  • N Offline
                    N Offline
                    NoumanYosuf
                    wrote on last edited by NoumanYosuf
                    #8

                    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
                    0

                    • Login

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