PDA

View Full Version : ToolBars with different height



Radagast
27th July 2008, 11:39
Qt 4.4.0
There are 2 QToolBars in the same area, for example Qt::TopToolBarArea. I want to make one of them higher, so it can include several rows of buttons, but the neighbour adjusts itself, so it has the same height, it looks ugly. How can I make toolbars that are in the same area have different height (if Top or bottom area) or width (if right or left area)?
testtoolbar.h

#ifndef TESTTOOLBAR_H
#define TESTTOOLBAR_H

#include <QtGui/QMainWindow>


class TestToolBar : public QMainWindow
{
Q_OBJECT

public:
TestToolBar(QWidget *parent = 0, Qt::WFlags flags = 0);
~TestToolBar();
public slots:
void changeToolBar2height();
private:
QToolBar* ToolBar1,*ToolBar2;
};

#endif // TESTTOOLBAR_H

testtoolbar.cpp

#include <QtGui>
#include "testtoolbar.h"

TestToolBar::TestToolBar(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
QAction* newAct = new QAction(QIcon(":/Resources/new.png"), tr("&New"),this);
QAction* saveAct = new QAction(QIcon(":/Resources/save.png"), tr("&Save"),this);
QAction* exitAct = new QAction(QIcon(":/Resources/exit.png"), tr("&Exit"),this);
QAction* copyAct = new QAction(QIcon(":/Resources/copy.png"), tr("&Copy"),this);
QAction* cutAct = new QAction(QIcon(":/Resources/cut.png"), tr("C&ut"),this);
QAction* pasteAct = new QAction(QIcon(":/Resources/paste.png"), tr("&Paste"),this);
ToolBar1 = addToolBar("ToolBar1");
ToolBar1->addAction(newAct);
ToolBar1->addAction(saveAct);
ToolBar1->addAction(exitAct);
ToolBar2 = addToolBar("ToolBar2");
ToolBar2->addAction(copyAct);
ToolBar2->addAction(cutAct);
ToolBar2->addAction(pasteAct);
connect(newAct,SIGNAL(triggered()),this,SLOT(chang eToolBar2height()));
}

TestToolBar::~TestToolBar()
{

}
void TestToolBar::changeToolBar2height()
{

QSizePolicy pol (QSizePolicy::Fixed,QSizePolicy::Fixed);
ToolBar1->setSizePolicy(pol);//didn't help
ToolBar2->setMinimumHeight(70);
}

Radagast
27th July 2008, 12:17
btw if I use simple resize(w,h), it works fine (the neighbour isn't affected) but the result is very temporal.