PDA

View Full Version : [qt3]invisible toolbar



lszk
26th February 2006, 18:12
I have a QMainWindow class object with menu and toolbar. When I compiled it everything was OK. But when I added a QVBoxLayout class object with rest stuff, I cannot see a toolbar. Only menu. What must I do to repair it? My constructor looks that:

dialog::dialog(QWidget *parent, const char *name) : QMainWindow(parent, name)
{
setGeometry(200,200,500,300);

QMenuBar *menu = new QMenuBar(this);
QPopupMenu *popup = new QPopupMenu(this);
QToolBar *toolbar = new QToolBar();
QToolButton *toolbutton = new QToolButton(QPixmap("fileopen"), "test","lszk",this,
SLOT(wyjscie()),toolbar);

popup->insertItem("&ttt",this,SLOT(info()));
menu->insertItem("&popup",popup);
addToolBar(toolbar);

QListBox *lista = new QListBox(this);
QPushButton *button = new QPushButton("ok",this);
QPushButton *button2 = new QPushButton("anuluj",this);
QVBoxLayout *pionowy = new QVBoxLayout(this);
QHBoxLayout *poziomy = new QHBoxLayout(this);

for(int i=1;i<=10;++i)
{ QString string = QString("Element numer %1").arg(i);
lista->insertItem(string); }

poziomy->addStretch();
poziomy->addWidget(button);
poziomy->addWidget(button2);
pionowy->addWidget(lista);
pionowy->addLayout(poziomy);
//resize(200,150);
}

jacek
26th February 2006, 18:18
QMainWindow uses it's own layout, so you must use QMainWindow::setCentralWidget().

Try this:
dialog::dialog(QWidget *parent, const char *name) : QMainWindow(parent, name)
{
// ...
QWidget *widget = new QWidget( this );
QListBox *lista = new QListBox( widget );
// ...
QVBoxLayout *pionowy = new QVBoxLayout( widget );
QHBoxLayout *poziomy = new QHBoxLayout( widget );
// ...
pionowy->addLayout( poziomy );
setCentralWidget( widget );
}

lszk
26th February 2006, 19:34
Thanks a lot. It works.