PDA

View Full Version : How to indent a text from left to right in a QListWidget?



harish
25th November 2011, 10:24
Hi,
I am having a QListWidget which displays the information about the user, for example:
User Name:
Place:
Address:
Time:


Now i need to move the time to the right corner and display it as follows:
User Name:
Place:
Address:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxTime:

Is there any code for this so that i can get displayed my time in the right corner?

What is the next thing i need to do?Anyone help me with this.Thanks in advance.

Regards,
Harish

Lykurg
26th November 2011, 08:31
Hi, your have to write your own item delegate where you define the drawing of the content.

ChrisW67
27th November 2011, 06:13
Is each line a separate item in the model, or is that a single entry of four wrapped lines?

If separate items, does the QListWidget honour the Qt::TextAlignmentRole from the items in model?

harish
28th November 2011, 05:08
Hi,
Each one is a different item and i need to display the time at the end.

I am trying with QListwidgetItem::setTextAlignment.....

Is that right?
I have declared a QListWidgetItem and i have used settextalignment for it.

ChrisW67
28th November 2011, 22:00
I was thinking of using setData() directly, but setTextAlignment() works too.


#include <QtGui>
#include <QDebug>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QListWidget lw;

QListWidgetItem *item1 = new QListWidgetItem("Line1");

QListWidgetItem *item2 = new QListWidgetItem("Line2");
item2->setData(Qt::TextAlignmentRole, Qt::AlignRight);

QListWidgetItem *item3 = new QListWidgetItem("Line3");
item3->setTextAlignment(Qt::AlignCenter);

lw.addItem(item1);
lw.addItem(item2);
lw.addItem(item3);

lw.show();

return app.exec();
}

harish
29th November 2011, 04:36
Thank you chris for your reply.

I had tried the coding with your help and it runs.

Now i am trying to combine all items in a single one which means a single item in which time is displayed at the right end.

Is that possible help me with this?

Thanks in advance,
Regards
Harish.M

ChrisW67
29th November 2011, 04:43
See Lykurg's answer.

Have you considered using a two column table rather than a list?

harish
30th November 2011, 10:28
Hi,
I am having a QListWidget which displays the information about the user, for example:
User Name:
Place:
Address:
Time:


Now i need to move the time to the right corner and display it as follows:
User Name:
Place:
Address:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxTime:
I am using four contents in a list and the fourth content should move to the right corner.
There are more number of items in the listwidget.In each the fourth content should move to the right corner.


Is it possible?What i should do?



Is there any code for this so that i can get displayed my time in the right corner?
Anyone help me with this.Thanks in advance.

Regards,
Harish

Qiieha
30th November 2011, 10:44
Look at the documentation for QListWidgetItem.
You can set the alignment for each Item....

Lykurg
30th November 2011, 12:44
Hi,

please do not double post your issue. And the answer has already been given: use a custom delegate! To read about that, start with the detailed description of QItemDelegate.

Best