PDA

View Full Version : QWidget containing two QToolButtons



momesana
1st October 2007, 22:34
Hi! I want to set a QWidget that is composed of two QToolButtons as the cornerWidget of a QTabWidget, but it doesnt work. The buttons are being squeezed and aren't usable any more. Outside of the QTabWidget the widget looks ok.

Any Ideas?
Thanx



#include <QApplication>
#include <QtGui>

// #include "main.moc"
int main(int argc, char **argv)
{
QApplication app(argc, argv);

QWidget *w = new QWidget;
QToolButton * butA = new QToolButton;
QToolButton * butB = new QToolButton;
// layout
QHBoxLayout * lo = new QHBoxLayout(w);
lo->addWidget(butA);
lo->addWidget(butB);

QTabWidget * tabWidget = new QTabWidget;
tabWidget->addTab(new QWidget(), "test tab");
tabWidget->setCornerWidget(w, Qt::TopRightCorner);
tabWidget->show();
return app.exec();
}

wysota
1st October 2007, 23:19
I think you'll need to alter the width and height of scrollbars to be able to put a larger than expected widget there. And that involves changing the application style or enforcing static sizes through manual setMinimumSize() calls.

momesana
1st October 2007, 23:25
Someone in the qt irc room pointed me towards another solution. setting the Layouts contents margin to 0.
QLayout::setContentsMargins(0,0,0,0); does the job. he docs say: "Only the horizontal element of the corner will be used.".

That's what I was told in the irc channel:


the corner widget respects the horizontal sizehint, but not the vertical, so it was allocating extra horizontal height for the margins, but not vertically... instead it squashed it.

Applied the proposed change and it works.

Thanks