How do I add a QTCreator-like left bar to my program?
I'm designing the GUI for a project, and I want a left bar like this ones
How do I put them in my .ui file?
You can try to use QToolBar with vertical orientation. To emulate tabs behavior you should put actions to QActionGroup and make them checkable.
For example to create left panel Qt creator like:
welcomeAct = new QAction(...)
toolbar->addAction(welcomeAct)
editAct = new QAction(...)
toolbar->addAction(editAct)
designAct = new QAction(...)
toolbar->addAction(designAct)
...
//add spacing
QLabel *spacing = new QLabel;
spacing->setSizePolicy(Qt::Expanding, Qt::Expanding);
toolbar->addWidget(spacing);
//adding aditional actions
runAct = new QAction(...)
toolbar->addAction(runAct)
runDebugAct = new QAction(...)
toolbar->addAction(runDebugAct)
buildAct = new QAction(...)
toolbar->addAction(buildAct)
// put "tabs" action in QActionGroup
group = new QActionGroup(this);
group->addAction(welcomeAct)
group->addAction(editAct)
group->addAction(designAct)
...
Simplest way - is to use QtCreator's library libCorePlugin.so and corresponding includes (FancyTabBar.h) from QtCreator's srcs
You can most likely do it by putting everything into a QHBoxLayout, where the left hand side is a QVBoxLayout column of QPushButton's with icons matching what you want. Have the buttons trigger what the right hand pane looks like.
There is also the QTabBar which does most of this work for you. You just need to tell it to put the tabs on the left hand side.
精彩评论