PDA

View Full Version : QComboBox Margins



ToddAtWSU
14th August 2006, 16:22
I am trying to set the margins inside a QComboBox so I can add some padding on the inside of the combo box so the longest item doesn't go from border to border. I called the function setContentsMargin( int, int, int, int ) but this doesn't seem to work. I have tried setting all 4 ints to 100 meaning I should have a giant margin, but when the combo box displays, I am lucky to have a margin of 1. I added in a resizeEvent( ) handler so I could see if the combo box was being resized anywhere else, but my qDebug statement inside the resizeEvent is only being called when I call the setContentsMargin function. Does anyone have any ideas why the setContentsMargin seems to be not working? Thanks!

wysota
19th August 2006, 12:58
You might want to try a different approach. QComboBox uses an internal model-view mechanism to display data (it is really a kind of a simple view, where the model is the list of items to display). As you can access the view (which is used when the box pops up), model and the delegate, you can change the delegate or model data. If you change the delegate so that it returns bigger sizeHints (or change sizeHintRole in items), it is possible, that the width of the combobox will change too (even in "not poped-up" mode).