Toolstrip equivilant
-
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:
widget.h
@
#ifndef WIDGET_H
#define WIDGET_H#include <QtGui>
class Widget : public QWidget
{
Q_OBJECTpublic:
Widget(QWidget *parent = 0);
~Widget();private:
QTabWidget *tabWidget;
QWidget *tab;
QToolBar *toolBar;
};#endif // WIDGET_H
@widget.cpp
@
#include "widget.h"Widget::Widget(QWidget *parent) : QWidget(parent)
{
resize(640,480);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);
}
Widget::~Widget(){}
@main.cpp
@
#include <QtGui/QApplication>
#include "widget.h"int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();return a.exec();
}
@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.