[Qt-interest] QVBoxLayout with 100s of items is hanging
Andre Somers
andre at familiesomers.nl
Fri Nov 27 10:48:19 CET 2009
Hi,
Some observations:
First of all, it looks like you have a major memory leak in your code.
You're creating QLabels on the heap, and you're not disposing of them.
Also, creating a new QLabel for every draw of every element sounds like
overkill to me.
You did not say before that you want clickable links in your items as
well. That is a bit tricky indeed. The way you are working, it is
obvious the links don't work. You only draw render the label's contents
in your view, but you are not using the label itself, so nothing gets
handled in terms of interaction. Don't do it like that. What you might
do, is take a look at QLabel's sources to see how it renders it's text
and handles it's clicks, and see if you can use that.
There are of course more ways of working here. If you want interaction,
a real widget would be nice, but you do need a list-view like system.
These are not so easy to combine. I used a part of the KDE project to do
that, known under the name Goya or KWidgetItemDelegate. The sources are
easy to find and LGPL licenced, so you may be able to use them. This
delegate allows you to put widgets in your view. It's not too hard to
deal with, but it's not a perfect solution. Still, I am using it in
exactly the way you are: checkboxes and clickable links with rich text
in a list view. That works.
Another approach you may try, is to simply use one big HTML view.
QWebView can display your stuff just fine, but you'll need a little bit
of trickery to get to your checkboxes (I think a bit of JavaScript will
be needed). Nothing major or overly complicated, but still. You will be
notified of link clicks though, nothing to worry about there. You will
need to use HTML and stylesheets to make it look nice though.
André
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));
>
> }
>
>
> Thank you!
>
> ------------------------------------------------------------------------
> *From:* Sean Harmer <sean.harmer at maps-technology.com>
> *To:* qt-interest at trolltech.com
> *Sent:* Thu, November 26, 2009 2:43:32 PM
> *Subject:* Re: [Qt-interest] QVBoxLayout with 100s of items is hanging
>
> Hi,
>
> On Thursday 26 November 2009 12:28:42 Qt Quest wrote:
> > One more thing that I want to note is that on the screen only about 30
> > lines are being shown in the scrollable layout. Maybe it is possible to
> > defer the computations until the items are actually shown when the
> layout
> > is scrolled down?
>
> As I suggested earlier if you use the model/view approach you will get
> this
> for free. Only those items in the view will be queried by the view for
> their
> actual data.
>
> > Maybe it is possible to hasten the display of the layout using fixed
> sizes?
>
> QTreeView::setUniroformRowHeights( true ) will do this optimisation
> for you.
>
> > Is this slow performance the destiny of every application with that
> much of
> > GUI controls? Thank you!
>
> Having 1300 rows of widgets is really pushing things too far. Much
> better to
> have one widget designed to show that much data efficiently.
>
> Just try it. Writing a simple table model is really not that hard to do.
>
> You can always come back to the list with questions if you get stuck
> writing
> the model.
>
> Sean
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list