QTabWidget tab with splitter



  • 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?


  • Lifetime Qt Champion

    Hi,

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


  • Qt Champions 2016

    • 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



  • 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!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.