[Qt-interest] When does a custom widget need a custom sizeHtin() ?
Stephen Collyer
scollyer at netspinner.co.uk
Mon Dec 14 12:21:07 CET 2009
2009/12/14 Sean Harmer <sean.harmer at maps-technology.com>
>
>
> >
> > When does a custom widget require a custom sizeHint() ? Maybe when it's
> not
> > a simple composition of widgets inside a QLayout ?
>
> Easy way to try it is to put your custom widget into a layout and see if it
> behaves as expected. If it does then great. If not then implement your own
> custom sizeHint() function.
>
>
I ask the question as I'm trying to get a custom widget to render correctly
in a QListWidget, by overriding QItemDelegate. Now, I'm not sure how to do
this properly, but I've written a new trivial paint method thus:
void QuestionSelectorDelegate::paint( QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index)
const
{
QuestionSelector qsel(1);
qsel.setGeometry(option.rect);
qsel.render(painter, option.rect.topLeft());
}
but this renders incorrectly. It looks like QListWidget doesn't get a proper
sizeHint and allocates too little space for it (maybe. I'm not sure). So I
thought about playing around with sizeHint() in the original widget, but
that seems to make no difference, probably becuase, as you have suggested,
it doesn't need one (as it's based on a QLayout).
--
Stephen Collyer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091214/36480bc6/attachment.html
More information about the Qt-interest-old
mailing list