Results 1 to 8 of 8

Thread: font color of list view

  1. #1
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default font color of list view

    hello every on i want to ask that i have a list view in which values are loaded from the file i want to ask that can i change font color of the list view as i have search the option but it does not give option to change font color plz help me


    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: font color of list view

    Are you using QListView with a model, or a QListWidget?
    In both cases you have to set the font in the item, not the list.
    See QListWidgetItem.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: font color of list view

    sir i didnt get u how to change font color in item can u kindly quid me little more .
    thanks

  4. #4
    Join Date
    Apr 2010
    Location
    Sudan
    Posts
    46
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: font color of list view

    You can change font color form Style Sheet .

    Righ click on the list view and chose change style sheet >add color>color

  5. #5
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: font color of list view

    actually for i want different color for different item in the list like i want some row to be red and some to be green based on some values. how can i do that
    thanks

  6. #6
    Join Date
    Apr 2010
    Location
    Sudan
    Posts
    46
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: font color of list view

    i tried to do it by using HTML Markup but it didn't work .. it seems like it only work with text Widgets.

    i don't think it is possible to change a single item color in list view.

  7. #7
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: font color of list view

    ok sir thanks but can any one tell me how to use that QBrush and foreground option of qlistwidgetitem my it will help solving problem

  8. #8
    Join Date
    Apr 2011
    Posts
    61
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: font color of list view

    You can create custom QListWidgetItem and use a "index-based" color.

    Qt Code:
    1. class ColouredItem : QListWidgetItem
    2. {
    3. private:
    4. static const int numberOfColors = 3;
    5. static QColor ColouredItem::colorList[numberOfColors];
    6.  
    7. public:
    8. void updateItemColor()
    9. {
    10. int row = this->listWidget()->row(this);
    11. this->setForeground(QBrush(colorList[row % numberOfColors]));
    12. }
    13. }
    14.  
    15. QColor ColouredItem::colorList[numberOfColors] = {QColor::fromRGB(255, 0, 0), QColor::fromRGB(0, 255, 0), QColor::fromRGB(0, 0, 255)};
    To copy to clipboard, switch view to plain text mode 

    When you need to update the color just call that updateItemColor function.

    If you need a "type-based color". Just change the colorList[row % 3] to get color based on type or something else.

Similar Threads

  1. List View with sections for alphabetialy sorted list
    By woodtluk in forum Qt Programming
    Replies: 4
    Last Post: 12th October 2010, 11:50
  2. Replies: 8
    Last Post: 6th May 2010, 11:17
  3. QTextDocument - color, font
    By kemp in forum Qt Programming
    Replies: 6
    Last Post: 24th January 2007, 13:51
  4. How do I change the font color in QTextBrowser?
    By probine in forum Qt Programming
    Replies: 2
    Last Post: 29th November 2006, 12:08
  5. Change Font Color of Label and CheckBox
    By mahe2310 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 15th June 2006, 10:24

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.