This seems to work for me:
Code:
#include <QtGui>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow() { }
bool event ( QEvent * event ) {
switch(event->type()) {
case QEvent::StyleChange:
if (m_tb->orientation() == Qt::Horizontal)
m_tb->setOrientation(Qt::Vertical);
else
m_tb->setOrientation(Qt::Horizontal);
}
}
private:
QToolBar *m_tb;
};
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
m_tb = new QToolBar();
QAction *act1 = new QAction("Test", this);
QAction *act2 = new QAction("Test2", this);
m_tb->addAction(act1);
m_tb->addAction(act2);
QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(m_tb);
m_tb->setLayout(layout);
setCentralWidget(m_tb);
}
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow w;
w.show();
return app.exec();
}
You might wanna re-position the toolbar depending the orientation AND make it fixedWidth in vertical orientation, but the basic case should work.