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. QTabWidget tab with splitter
QtWS25 Last Chance

QTabWidget tab with splitter

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 2.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.
  • SikarjanS Offline
    SikarjanS Offline
    Sikarjan
    wrote on last edited by Sikarjan
    #1

    Hi,

    I am using code to generate new tabs in my QTabWidget. I managed to get the content I want but I cannot make it fill the tab. In all the examples I looked it seems to be the default behaviour but nor for me. Here is the code I use to generate the content of the tab:

        QWidget *page = new QWidget;
        QSplitter * editorSplitter = new QSplitter(page);
        QBoxLayout * tabLayout = new QBoxLayout(QBoxLayout::LeftToRight);
        editorSplitter->addWidget(editor);
        editorSplitter->addWidget(finder);
        finder->hide();
    
        int index = ui->tabWidget->insertTab(ui->tabWidget->count()-1, page, "opening...");
        ui->tabWidget->setCurrentIndex(index);
        ui->tabWidget->widget(index)->setLayout(tabLayout);
    

    editor and finder are to classes I made myself. Editor derived from QPlainTextEdit and finder is a QWidget I created as Qt Designer Form Class to create a search dialog.

    The right thing to do is probably to set the splitter as central widget but QWidget has no centralWidget. Setting a layout does not help either, so what am I doing wrong?

    [Update]
    I've been doing some additional research. There is no example out there with a QTabWidet and a QSplitter. If I try to add a splitter in Designer it is not possible because the splitter option is greyed out. Is it not allowed to have a splitter on a tab?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why not put your splitter in tabLayout ?
      Also, why not put editorSplitter directly in the QTabWidget ?

      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
      1
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3
        • Designer it is not possible because the splitter option is greyed out. Is it not allowed to have a splitter on a tab?

        Place 2 Widgets first, select both, then Splitter is available.
        alt text

        1 Reply Last reply
        2
        • SikarjanS Offline
          SikarjanS Offline
          Sikarjan
          wrote on last edited by
          #4

          Sorry for the noob question. I did not understand the splitter and tab concept correctly. I thought I had to create a page widget first and then put in the things I want.

              QSplitter * editorSplitter = new QSplitter(page);
              editorSplitter->addWidget(editor);
              editorSplitter->addWidget(finder);
              finder->hide();
          
              int index = ui->tabWidget->insertTab(ui->tabWidget->count()-1, editorSplitter, "opening...");
              ui->tabWidget->setCurrentIndex(index);
          

          Is all it takes to put the splitter in the tab widget.

          Thanks for the help though!

          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