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. How to resize QSplitter automatically according to QWidget

How to resize QSplitter automatically according to QWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
qsplitterqwidget
4 Posts 3 Posters 4.6k 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.
  • N Offline
    N Offline
    NIXIN
    wrote on 12 Sept 2016, 12:50 last edited by
    #1

    I have tried something like below:

    QWidget *wid = new QWidget;

    QSplitter *hSplitter = new QSplitter(Qt::Horizontal, wid);

    QTabWidget *tWid = new QTabWidget;
    QTextBrowser *tBrowser = new QTextBrowser;

    hSplitter->insertWidget(0, tWid);
    hSplitter->insertWidget(1, tBrowser);
    hSplitter->setHandledWidth(0);

    wid->show();

    what I want is that QSplitter should automatically resize according to QWidget, when the window is minimized or maximized

    but its not happening

    QSplitter size is fixed, it is not resizing.

    Please suggest how to achieve it.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 12 Sept 2016, 13:25 last edited by
      #2

      You have to insert the splitter in a layout

      QWidget *wid = new QWidget;
      
      QSplitter *hSplitter = new QSplitter(Qt::Horizontal, wid);
      QHBoxLayout* widLay=new QHBoxLayout(wid);
      hSplitter->addWidget(hSplitter);
      // all the rest
      

      Btw, make sure you are not leaking memory in wid, give it a parent or handle the delete

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • N Offline
        N Offline
        NIXIN
        wrote on 13 Sept 2016, 05:19 last edited by NIXIN
        #3

        I tried what you suggested with a little change

        QWidget *wid = new QWidget;
        
        QSplitter *hSplitter = new QSplitter(Qt::Horizontal, wid);
        QHBoxLayout* widLay=new QHBoxLayout(wid);
        widLay->addWidget(hSplitter);
        

        This works fine when I run the code, and show the QWidget (here wid) from the menu.

        But when I close it and again show the QWidget from the menu, widLay is not covering the entire widget, only some part in the top left corner, and rest widget is blank.

        And I also observe something on command line:
        setGeometry: UInable to set geometry 540x241+1366+22 on QWidgetWindow........

        Please suggest how to solve this.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 13 Sept 2016, 20:08 last edited by
          #4

          Hi,

          Out of curiosity, why use a QSplitter at all since you don't use it of any resizing operation ?

          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

          1/4

          12 Sept 2016, 12:50

          • Login

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