Qt Forum

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

    [SOLVED]about QSplitter collapse issue

    General and Desktop
    2
    4
    6264
    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.
    • Z
      zhanguoxiaoyan last edited by

      The problem is that I want to use the collapse of one splitter to trigger another splitter collapse.

      The brief descriptions are as figure shown,

      !http://i.imgur.com/eRfVP.png(chart)!

      In the mainwindow, splitters make it become 3 parts. While dragging the handle1, the window can finally display only 2 parts(1 and 3), 2 is collapsed.

      However, how can I only drag the handle1 to collapse both part 2 and 3? I know if I drag handle2, it is ok. but with only handle1, I have no idea...

      I have checked the corresponding reference and thought about the splitterMoved(int pos, int index), but still do not have a clear solution yet...

      Thanks!

      1 Reply Last reply Reply Quote 0
      • R
        rschaub last edited by

        you could attach a slot to the 'splitterMoved' signal

        @
        void CMyWidgetW::SlotSplitterMoved(int iPos, int iIndex)
        {
        QList<int> sizeList = sizes();
        if (<index of interest> == iIndex && 0 == sizeList[iIndex])
        {
        sizeList.clear();
        sizeList << size().width() << 0 << 0;
        pSplitter->setSizes(sizeList);
        }
        }
        @

        The idea is that whenever you move a splitter, you detect whether the widget in question is collapsed. If that's the case, you'll force the other widget to collapse as well by assigning it the size 0.

        note: I haven't tried this, so I can't guarantee it'll work...

        1 Reply Last reply Reply Quote 0
        • Z
          zhanguoxiaoyan last edited by

          I've tried your method, it works! Thanks!

          However I found a thing:

          if I modified the code to reverse the case which means I drag handle3 to collapse both part1 and part2. For example,

          @QList<int> Splittersize = ui->splitter->sizes();
          if (index == 2 && 0 == Splittersize[index-1])
          {
          Splittersize.clear();
          Splittersize << size().width() << 0 << 0;

          ui->splitter->setSizes(Splittersize);
          

          }@

          Then the handle2 and handle3 will both goto the right side. Not the left side. The same with the case of trying to drag handle2 to collapse part2 and part3 (it seems logistical).

          I tried to use maximumWidth() instead of 0, but doesn't work as excepted.

          So how can I modify the codes to make it also work in this reverse case?

          1 Reply Last reply Reply Quote 0
          • R
            rschaub last edited by

            if you want to reverse the behaviour so that you can drag handle 3 (or 2 in your drawing) to the left, use something like this:

            @
            void CMyWidgetW::SlotSplitterMoved(int iPos, int iIndex)
            {
            QList<int> sizeList = sizes();

            if (2 == iIndex && 0 == sizeList[1])

            {
            sizeList.clear();
            sizeList << 0 << 0 << size().width();
            pSplitter->setSizes(sizeList);
            }
            }
            @

            sizeList contains the width for all the widgets contained within the splitter, ordered in a left-to-right fashion.

            So if you want to hide the leftmost widget, your first width in 'sizeList' has to be 0, the second size has to be 0 as well (since that's the one you've actually collapsed), and the last one has to span the whole width of the splitter (theoretically, you'd have to subtract the handle sizes).

            1 Reply Last reply Reply Quote 0
            • First post
              Last post