You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Saturday, February 26th 2005, 4:33am

can QCombobox change size?

Hello,

How can I make it so that a QComboBox is wider when it drops down than when it is closed?

Thank you,

Math

hatulflezet

Professional

Posts: 1,301

Location: Munich Germany

Occupation: Programmer

  • Send private message

2

Sunday, February 27th 2005, 2:34am

how about :void QWidget::resize ( const QSize & )
Click here! I dare ya'!! :]
Project Archimedes
----------------------------------------------------------
"Don't panic, and thanks for all the fish!"

Lykurg

Trainee

  • "Lykurg" is male

Posts: 92

Location: Germany

Occupation: Student

  • Send private message

3

Sunday, February 27th 2005, 7:56am

Quoted

Originally posted by hatulflezet
how about :void QWidget::resize ( const QSize & )
Of course, but how do you know if it is currently droped down?
I understand the question, that he want to have a combobox with the with e.g. 100px and if it is dropped it should have the with 200px, and 100px again if it is closed.

hatulflezet

Professional

Posts: 1,301

Location: Munich Germany

Occupation: Programmer

  • Send private message

4

Sunday, February 27th 2005, 1:35pm

Hmm... if what you want is catching the drob down evemt,then the imidate thing I see is:
popDownListBox();

But it is private, so subclssing will be needed.

Maybe there is a better way, but I can't see it at the moment.
Click here! I dare ya'!! :]
Project Archimedes
----------------------------------------------------------
"Don't panic, and thanks for all the fish!"

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

5

Sunday, February 27th 2005, 2:26pm

Quoted

Originally posted by Lykurg

Quoted

Originally posted by hatulflezet
how about :void QWidget::resize ( const QSize & )
Of course, but how do you know if it is currently droped down?
I understand the question, that he want to have a combobox with the with e.g. 100px and if it is dropped it should have the with 200px, and 100px again if it is closed.


It's not very wise to resize the whole combobox as it can ruin the whole layout of the parent widget.

Lykurg

Trainee

  • "Lykurg" is male

Posts: 92

Location: Germany

Occupation: Student

  • Send private message

6

Monday, February 28th 2005, 4:42am

Quoted

Originally posted by wysota
It's not very wise to resize the whole combobox as it can ruin the whole layout of the parent widget.


I don't know what HonestMath exactly want do, but I guess if you have a combobox with realy huge option-string-size, it wuold be nice to read the hole strings if it is dropped down. If not active it is enough to read just the beginning, and for the short time dropped down, the parentlayout isn't important. And when dropped in, all is normal as before.

For what else this behavior could be good, my crystal ball won't tell me X(

blue death

Beginner

  • "blue death" is male

Posts: 51

Location: somewhere in space and time

Occupation: cs-student

  • Send private message

7

Monday, February 28th 2005, 2:21pm

this is a common problem with listboxes - long strings get truncated.
i was thinking of some way to solve this but i still have to do some tests.

one way to solve the problem may be setting a custom QListBox class that resizes itself correctly (when show() is called) for the comboBox (there is a setListBox(..) method)

i don't know if it works yet :)
don't dream, if you want your dreams to become true

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

8

Monday, February 28th 2005, 2:35pm

QComboBox has a listBox() member which returns a pointer to a QListBox which is part of the combo box. You can resize the listBox only if you wish, but leave the whole QComboBox alone.

blue death

Beginner

  • "blue death" is male

Posts: 51

Location: somewhere in space and time

Occupation: cs-student

  • Send private message

9

Monday, February 28th 2005, 3:00pm

ok, i made some tests :D

i subclassed QListBox by overwriting the show() method and adding these stupid lines:

resize((int)maxItemWidth(), size().height());
QListBox::show();

this should work, althought there should be some check to ensure you dont get a 20000 pixel wide list .. that wont look so nice :)

there are other ways to resize the list.. you could connect some combobox signal to a slot where you do the work, subclass combobox so it resizes its list as soon as the contents of the box change (both solutions use the listBox() method suggested by wysota that i missed while reading the docs X(), subclass qlistbox and put those stupid lines somewhere else (resizing at every show() isnt really smart :rolleyes: )

ps: there is a property called variableWidth in the ListBox class. documentation says "each column is as wide as the widest item in that column" if this property is true... but it doesnt work here :rolleyes:
don't dream, if you want your dreams to become true

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

10

Monday, February 28th 2005, 3:35pm

Did you do setColumnMode(Variable) ? I think it is necessary for variable width to work.

blue death

Beginner

  • "blue death" is male

Posts: 51

Location: somewhere in space and time

Occupation: cs-student

  • Send private message

11

Monday, February 28th 2005, 4:03pm

Quoted

Originally posted by wysota
Did you do setColumnMode(Variable) ? I think it is necessary for variable width to work.


no, i think it has nothing to do with the width of a column. i think its only about the number of visible columns/rows (a listbox can display multiple columns too)
i deleted the example code and i dont want to test it again right now ;)
i will make a new post if i can test it and it works :))
don't dream, if you want your dreams to become true