Important: Please read the Qt Code of Conduct -

A few big questions about splitter windows

  • My first question is... why won't this code work?
    @#include <QApplication>
    #include <QSplitter>
    #include <QListView>
    #include <QTreeView>
    #include <QTextEdit>

    int main(int argc, char *argv[])
    QApplication app(argc, argv);

    QSplitter *splitter = new QSplitter;
    QListView *listview = new QListView;
    QTreeView *treeview = new QTreeView;
    QTextEdit *textedit = new QTextEdit;
    return app.exec();


    It compiles with no errors, but when I run it nothing shows up. Do I need to initialize the parent parameter, and if so to what? Forgive me as I'm rather new to Qt programming.
    And antoher question, how do I use QSplitterHandle, and how is it implemented differently from QSplitter?

  • You forgot to show splitter.

  • About your second question, let me quote the "documentation":

    The QSplitterHandle class provides handle functionality of the splitter.

    QSplitterHandle is typically what people think about when they think about a splitter. It is the handle that is used to resize the widgets.

    A typical developer using QSplitter will never have to worry about QSplitterHandle. It is provided for developers who want splitter handles that provide extra features, such as popup menus.

  • I apologize about the splitterhandle question, they just slip through sometimes I guess. xD I'll look more carefully next time.

    The show function worked by the way, thanks! I do have another question though, is there a standard way to create a type of "quad splitter" (or splitter that has both horizontal and vertical properties)? One thing that comes to mind is I could have 2 horizontal child splitters, each with two, say, opengl viewports, and then I would add these splitters to a vertical parent splitter. But is there a more standard way to do this that Qt already has implemented?

    EDIT: I've tried implementing the splitter in the way I described. The horizontal bar works correctly, but the vertical one acts like two separite bars. So that won't really work the way I thought.

  • A probable idea for such a construst you want to make, I think, is to make a QTableView, where each cell represented by a QWidget - this done by reimplementing QItemDelegate's all virtual functions.
    But it is a rather complicated way :)
    The other way I see is to reimplement QSplitter in a very simple way - add a slot, that just calls moveSplitter ( int pos, int index ) (it is a protected function). Then, you just connect splitterMoved( int pos, int index ) signal to new slot of other splitter for both your separate bars in example above. The only problem I see here is a probable infinite loop, if there is no protection in moveSplitter( int pos, int index ) (no checking for equality of new and old pos)

Log in to reply