Is there an equivalent of a .net Toolstrip, I'd like to "dock" some buttons at the top of a tab page ?
The equivalent of ToolStrip in Qt is "QToolBar":http://qt-project.org/doc/qt-4.8/qtoolbar.html. You can add one to the top of your tab's layout as follows:
class Widget : public QWidget
Widget(QWidget *parent = 0);
#endif // WIDGET_H
Widget::Widget(QWidget *parent) : QWidget(parent)
QVBoxLayout *l=new QVBoxLayout(this); tabWidget=new QTabWidget(this); l->addWidget(tabWidget); tab=new QWidget(this); tabWidget->addTab(tab, "Page 1"); QVBoxLayout *pl=new QVBoxLayout(tab); pl->setSpacing(0); pl->setContentsMargins(0,0,0,0); pl->setAlignment(Qt::AlignTop); toolBar=new QToolBar(this); toolBar->addAction(new QAction("Action 1", this)); toolBar->addAction(new QAction("Action 2", this)); toolBar->addAction(new QAction("Action 3", this)); pl->addWidget(toolBar);
int main(int argc, char *argv)
QApplication a(argc, argv);
This will look a bit odd on Mac because of the style of tabs but it will get you the same result as ToolStrip on Windows platforms.
Hope this helps ;o)
That's great thanks.
I've been reading around on doing this in the Designer but it doesn't seem possible. It seems you could define the toolbar in a separate ui file and then create a plugin derived from QDesignerCustomWidgetInterface and then you could create it within Designer or you could promote it but it doesn't seem to show the Widget in Designer. Is there any other way of doing this ?
I don't use Designer, but from what I remember, the assumption is that menus, toolbars and statusbars are main window (i.e. QMainWindow) elements so this is the only context in which you can use them (I will stand corrected on this though). If that is the case, and you want to use designer to create your UI rather than defining it in code, then I think you will have to create a custom element as you say. WRT to it not being visible in designer, I'm afraid I've not used it enough to comment.