[Qt-interest] QVBoxLayout with 100s of items is hanging
Sean Harmer
sean.harmer at maps-technology.com
Thu Nov 26 23:26:58 CET 2009
Hi,
Qt Quest wrote:
> OK, I've changed the code to a list view and great performance!
> Now in each line I show a checkbox and HTML text. I want the user to be
> able to check the checkbox and press the links in the HTML text.
> I'm trying to use a delegate, but I have few problems:
>
> 1. The HTML links in the label are not selectable - the cursor does not
> change to a pointer, and no event is generated. This is true also for
> the checkbox.
> 2. paint() function of delegate is the only one called..
>
> I'm using:
> ui.list->setItemDelegate(new MyDelegate());
>
>
> void MyDelegate::paint(QPainter *painter, const QStyleOptionViewItem
> &option, const QModelIndex &index ) const
>
> {
>
> QStyleOptionProgressBar progressBarOption;
>
> QCheckBox *check = new QCheckBox();
>
> check->setChecked(true);
>
> check->render(painter , QPoint(0,0));
>
> check->setMaximumSize(QSize(14,14));
>
> QLabel *label = new QLabel();
>
> label->setText("this <a href=\"b\">is a <b>test</b></a>");
>
> label->render(painter , QPoint(14,0));
>
> }
Why do it like this? Just use the Qt::CheckStateRole in your model's
data()/setData() functions. If you then also set the
Qt::ItemIsUserCheckable flag in the flags() function, the default
delegate will take care of drawing checkboxes for you.
Then as Andre suggested, you could derive a custom delegate to draw your
rich text and make the links interactive.
HTH,
Sean
More information about the Qt-interest-old
mailing list