PDA

View Full Version : ListWidget -> custom Item -> height



Archa4
3rd February 2011, 14:47
So mine question is: is there any way to make listWidgetItem occupy as much space as it needs (apposed to fixed size)? I use customised widget as items (2 labels + picture + Multi-line lable).

mcosta
4th February 2011, 10:52
Try using QListWidgetItem::setSizeHint().

Archa4
4th February 2011, 10:55
Try using QListWidgetItem::setSizeHint().

Unfortunately i don't know how much space will item occupy... As i said earlier, it contains 2 labels, image and multiline lable, which can be sized from 1 to 15 lines. How do I use setSizeHint in this situation?

mcosta
4th February 2011, 11:08
Unfortunately i don't know how much space will item occupy... As i said earlier, it contains 2 labels, image and multiline lable, which can be sized from 1 to 15 lines. How do I use setSizeHint in this situation?

You have to compute tha maximum size hint of single components.

Archa4
4th February 2011, 11:19
You have to compute tha maximum size hint of single components.

Well.. the maximum size of hints is the same... I tried to compine their heights using, for example:
name = new QLabel("Name");
int asd;
asd += int->height();
but all the labels have the same height, so i cannot define which items should be bigger, and which should be smaller...

mcosta
4th February 2011, 11:36
The size hint is computed by widget and depends on their content.

This code works


void Widget::on_computeButton_clicked()
{
int maximumSizeHint = 0;

QList<QLabel*> labels = this->findChildren <QLabel*> ();
Q_FOREACH (QLabel* lab, labels) {
int itemp = lab->sizeHint ().height ();

qDebug ("%s sizeHint.height = %d", qPrintable(lab->objectName ()), itemp);
if (itemp > maximumSizeHint)
maximumSizeHint = itemp;
}

qDebug ("Maximum sizeHint height = %d", maximumSizeHint);
}

The output is:


label sizeHint.height = 13
label_2 sizeHint.height = 13
label_3 sizeHint.height = 39
Maximum sizeHint height = 39

The widget is in attachment:5870