Results 1 to 10 of 10

Thread: How to indent a text from left to right in a QListWidget?

  1. #1
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Post How to indent a text from left to right in a QListWidget?

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to indent a text from left to right in a QListWidget?

    Hi, your have to write your own item delegate where you define the drawing of the content.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to indent a text from left to right in a QListWidget?

    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?

  4. #4
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: How to indent a text from left to right in a QListWidget?

    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.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to indent a text from left to right in a QListWidget?

    I was thinking of using setData() directly, but setTextAlignment() works too.
    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7.  
    8.  
    9. QListWidgetItem *item1 = new QListWidgetItem("Line1");
    10.  
    11. QListWidgetItem *item2 = new QListWidgetItem("Line2");
    12. item2->setData(Qt::TextAlignmentRole, Qt::AlignRight);
    13.  
    14. QListWidgetItem *item3 = new QListWidgetItem("Line3");
    15. item3->setTextAlignment(Qt::AlignCenter);
    16.  
    17. lw.addItem(item1);
    18. lw.addItem(item2);
    19. lw.addItem(item3);
    20.  
    21. lw.show();
    22.  
    23. return app.exec();
    24. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Post Re: How to indent a text from left to right in a QListWidget?

    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

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to indent a text from left to right in a QListWidget?

    See Lykurg's answer.

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

  8. #8
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Post How to indent a text from left to right corner?

    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

  9. #9
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to indent a text from left to right corner?

    Look at the documentation for QListWidgetItem.
    You can set the alignment for each Item....

  10. #10
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to indent a text from left to right corner?

    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

Similar Threads

  1. text indent with wrap
    By linuxsong in forum Qt Quick
    Replies: 1
    Last Post: 26th July 2011, 14:14
  2. left alignment for pushbutton text
    By BalaQT in forum Qt Programming
    Replies: 7
    Last Post: 22nd September 2009, 08:41
  3. QListView with icons on top of the text, not at the left
    By vfernandez in forum Qt Programming
    Replies: 7
    Last Post: 19th February 2009, 04:19
  4. [QTabWidget] horizontal text on left side
    By Boy in forum Qt Programming
    Replies: 6
    Last Post: 16th May 2008, 08:52
  5. how to srcoll a long text in one line from right to left?
    By deweyjew in forum Qt Programming
    Replies: 3
    Last Post: 21st November 2006, 10:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.