Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 9

Qt-interest Archive, March 2002
QComboBox sizeHint().width() is constant


Message 1 in thread

3.0.3 on Linux :


#include <qcombobox.h>
#include <qapplication.h>

#include <iostream>
 
int main( int argc, char **argv )
{
	QApplication a( argc, argv );
	QComboBox test( "blah" );
	a.setMainWidget( &test);
	test.show();
	test.insertItem("a");
	std::cerr << "width hint " << test.sizeHint().width() << std::endl;
	test.insertItem("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
	std::cerr << "width hint " << test.sizeHint().width() << std::endl;
	return a.exec();
}

both return 85 on my box. This makes a readable, well-sized combo on a
toolbar impossible as far as I can see.

Is this a bug ? If not, why ?

regards
john

-- 
 [ signature omitted ] 

Message 2 in thread

On Mon, 25 Mar 2002 23:47:03 +0000
John Levon <moz@compsoc.man.ac.uk> wrote:

> 3.0.3 on Linux :
> 
> 
> #include <qcombobox.h>
> #include <qapplication.h>
> 
> #include <iostream>
>  
> int main( int argc, char **argv )
> {
> 	QApplication a( argc, argv );
> 	QComboBox test( "blah" );
> 	a.setMainWidget( &test);
> 	test.show();
> 	test.insertItem("a"i, );
> 	std::cerr << "width hint " << test.sizeHint().width() <<
> 	std::endl; test.insertItem("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
> 	std::cerr << "width hint " << test.sizeHint().width() <<
> 	std::endl; return a.exec();
> }
> 
> both return 85 on my box. This makes a readable, well-sized combo on a
> toolbar impossible as far as I can see.
> 
> Is this a bug ? If not, why ?

I think the combobox size is only recomputed when it is shown : if you
move the test.show() statement after the second cerr and you will get a
much wider combobox.

Calling adjustSize() after the second insertItem does not seem to have any
effect either...

-- 
 [ signature omitted ] 

Message 3 in thread

On Tue, Mar 26, 2002 at 08:25:57AM +0000, Matthieu Dazy wrote:

> > Is this a bug ? If not, why ?
> 
> I think the combobox size is only recomputed when it is shown : if you
> move the test.show() statement after the second cerr and you will get a
> much wider combobox.

You are correct, thanks for this workaround. Does anybody know /why/
it's like this ?

regards
john

-- 
 [ signature omitted ] 

Message 4 in thread

On Tue, Mar 26, 2002 at 05:17:02PM +0000, John Levon wrote:
> On Tue, Mar 26, 2002 at 08:25:57AM +0000, Matthieu Dazy wrote:
> 
> > > Is this a bug ? If not, why ?
> > 
> > I think the combobox size is only recomputed when it is shown : if you
> > move the test.show() statement after the second cerr and you will get a
> > much wider combobox.
> 
> You are correct, thanks for this workaround. Does anybody know /why/
> it's like this ?

To make sizeHint() as fast as possible in the common case? :)


Simon