Jean-Marc Lasgouttes wrote:
> Angus> Here's the (much simpler) patch for 1.4 too.
> What happens when two toolbars are put on the same line? How does
> the filler behave?
It appears to create a small, but non-zero spacer. Try the attached,
changing the "#if 0" to "#if 1" to see the difference.
moc toolbar.h > toolbar.moc
g++ -I/usr/include/qt3 -o toolbar toolbar.cpp -lqt-mt
./toolbar
Personally, I'm quite comfortable with this small extra spacer. Are
you?
I've also sent a mail to the [EMAIL PROTECTED] mailing list,
asking what is the "best practice" way to achieve such a stretchable
toolbar. Will get back once the mail appears/someone replies. (There
appears to be some problem with the Qt ML ATM.)
--
Angus
#include "toolbar.h"
#include <qapplication.h>
#include <qpixmap.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <cassert>
#include <iostream>
#include <sstream>
namespace {
char const * cdtoparent_xpm[]={
"15 13 3 1",
". c None",
"* c #000000",
"a c #ffff99",
"..*****........",
".*aaaaa*.......",
"***************",
"*aaaaaaaaaaaaa*",
"*aaaa*aaaaaaaa*",
"*aaa***aaaaaaa*",
"*aa*****aaaaaa*",
"*aaaa*aaaaaaaa*",
"*aaaa*aaaaaaaa*",
"*aaaa******aaa*",
"*aaaaaaaaaaaaa*",
"*aaaaaaaaaaaaa*",
"***************"};
QToolBar * build_toolbar(QMainWindow * parent)
{
std::ostringstream ss;
static int count = 1;
ss << "toolbar" << count++;
char const * const toolbar_name = ss.str().c_str();
QToolBar * toolbar = new QToolBar(toolbar_name, parent, parent);
QToolButton * tb =
new QToolButton(QPixmap(cdtoparent_xpm), "One directory up",
QString::null, parent, SLOT(cdUp()),
toolbar, "cd up");
toolbar->addSeparator();
#if 0
tb = new QToolButton(toolbar, "");
tb->setEnabled(false);
toolbar->setStretchableWidget(tb);
#endif
return toolbar;
}
} // namespace anon
MyWindow::MyWindow()
{
resize(600,300);
QToolBar * toolbar1 = build_toolbar(this);
QToolBar * toolbar2 = build_toolbar(this);
toolBars(Qt::DockTop).append(toolbar1);
toolBars(Qt::DockTop).append(toolbar2);
}
void MyWindow::cdUp()
{
std::cout << "cd up" << std::endl;
}
#include "toolbar.moc"
int main(int argc, char * argv[])
{
QApplication qapp(argc, argv);
MyWindow * my_window = new MyWindow;
qapp.setMainWidget(my_window);
my_window->show();
return qapp.exec();
}
// -*- C++ -*-
#ifndef TOOLBAR_TEST_H
#define TOOLBAR_TEST_H
#include <qmainwindow.h>
class MyWindow: public QMainWindow {
Q_OBJECT
public:
MyWindow();
private slots:
void cdUp();
};
#endif // TOOLBAR_TEST_H