QListWidget adjust size to content

前端 未结 6 926
情话喂你
情话喂你 2020-12-05 09:48

Is it possible to adjust QListWidget height and width to it\'s content?

sizeHint() always returns 256, 192 no matter what its content is.

6条回答
  •  广开言路
    2020-12-05 10:17

    In order to effectively use sizeHint, you have to override it, at least in c++. In my experience, the default implementations for widgets can be pretty useless when you want a specific behavior. Attempts to force what you want with spacers or layouts end in disaster. If you can derive from QListWidget and override sizeHint, you can iterate through your items and find the longest string, then do some kind of magic to determine how wide it should be.

    That's what I'd do, anyway.

提交回复
热议问题