Results 1 to 7 of 7

Thread: Different text block colours in QListView (QListWidget)

  1. #1
    Join Date
    Apr 2008
    Posts
    26
    Thanks
    1

    Default Different text block colours in QListView (QListWidget)

    Is it possible to set different colours for text blocks in one list widget item in QListWidget (or any other widget not inherited from QTextDocument)?
    I think its possible do this by redefining paint method in QListWidget(any other widget) but maybe there is a simpler way like using QSyntaxHighlighter in QTextDocument?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Different text block colours in QListView (QListWidget)

    Its possible using delegates. You need to use setItemDelegate() function and handle the coloring in delegate.

    You can override drawDisplay() method of the delegate for ur rendering. And you can use syntax highlighter in your delegate

  3. #3
    Join Date
    Apr 2008
    Posts
    26
    Thanks
    1

    Default Re: Different text block colours in QListView (QListWidget)

    But is it possible to higlight blocks of text(single characters) in cases when i cant use delegates, for example in QLabel or QLineEdit?
    Last edited by rippa; 1st July 2008 at 16:39.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Different text block colours in QListView (QListWidget)

    Quote Originally Posted by rippa View Post
    But is it possible to higlight blocks of text(single characters) in cases when i cant use delegates, for example in QLabel or QLineEdit?
    QLabel supports rich text, QLineEdit doesn't.
    J-P Nurmi

  5. #5
    Join Date
    Jul 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Different text block colours in QListView (QListWidget)

    Quote Originally Posted by rippa View Post
    But is it possible to higlight blocks of text(single characters) in cases when i cant use delegates, for example in QLabel or QLineEdit?
    instead of qlineedit you can use QTextEdit if you want rich text

  6. #6
    Join Date
    Apr 2008
    Posts
    26
    Thanks
    1

    Default Re: Different text block colours in QListView (QListWidget)

    So the idea is to delegate(use ditrectly) QTextDocument (QTextEdit) if its possible and use QSyntaxHighlighter with it and it is impossible without overriding paint method to highlight text blocks in objects that dont inhererit from QTextDocument?

  7. #7
    Join Date
    Apr 2008
    Posts
    26
    Thanks
    1

    Default Re: Different text block colours in QListView (QListWidget)

    Thanks to all. Done it with delegating QTextEdit to my ListWidget.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. How to block the textedit'd text to be copied
    By santosh.kumar in forum Qt Programming
    Replies: 2
    Last Post: 2nd November 2007, 10:54

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.