Results 1 to 11 of 11

Thread: Changing color of SOME lineEdit / textEdit contents

  1. #1
    Join Date
    Mar 2015
    Posts
    24
    Qt products
    Qt5
    Platforms
    Windows

    Default Changing color of SOME lineEdit / textEdit contents

    How do you change the color of only certain parts of text in a lineEdit, when you append something to it?
    Like if I added
    Qt Code:
    1. Hello World, this is my program
    To copy to clipboard, switch view to plain text mode 
    to a lineEdit or textEdit, how do I change the "World," to blue and keep the rest black?

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Changing color of SOME lineEdit / textEdit contents

    Quote Originally Posted by BeautiCode View Post
    How do you change the color of only certain parts of text in a lineEdit, when you append something to it?
    Like if I added
    Qt Code:
    1. Hello World, this is my program
    To copy to clipboard, switch view to plain text mode 
    to a lineEdit or textEdit, how do I change the "World," to blue and keep the rest black?
    I do not know for sure, but I highly doubt you can do what you want with a QLineEdit. A QLineEdit operates on plain text only. A QTextEdit can be plain text of rich text.

    I don't know what type of app you are writing, but I recommend that you focus on the core functionality and don't waste your time trying to implement useless, non-standard features that users aren't used to seeing, etc...

  3. #3
    Join Date
    Mar 2015
    Posts
    24
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Changing color of SOME lineEdit / textEdit contents

    Quote Originally Posted by jthomps View Post
    I do not know for sure, but I highly doubt you can do what you want with a QLineEdit. A QLineEdit operates on plain text only. A QTextEdit can be plain text of rich text.

    I don't know what type of app you are writing, but I recommend that you focus on the core functionality and don't waste your time trying to implement useless, non-standard features that users aren't used to seeing, etc...
    Just because you can't find a solution, you decide to automatically assume that the feature I want to implement is useless?

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Changing color of SOME lineEdit / textEdit contents

    Quote Originally Posted by BeautiCode View Post
    Just because you can't find a solution, you decide to automatically assume that the feature I want to implement is useless?
    First of all, it's not my responsibility to find a solution for you. I have seen your multiple posts over the last couple of days and my opinion is that you should focus on the core functionality of your app and add the bells and whistles once you have working code.

    If you want to spend hours or days trying to implement something, by all means knock yourself out!

    I was simply trying to convey that what you want to achieve is non-standard and likely can't be implemented using a QLineEdit. But don't take my word for it, go for it.

    Best of luck to you in your quest.
    Last edited by jefftee; 28th March 2015 at 02:20.

  5. #5
    Join Date
    Mar 2015
    Posts
    24
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Changing color of SOME lineEdit / textEdit contents

    Quote Originally Posted by jthomps View Post
    First of all, it's not my responsibility to find a solution for you. I have seen your multiple posts over the last couple of days and my opinion is that you should focus on the core functionality of your app and add the bells and whistles once you have working code.

    If you want to spend hours or days trying to implement something, by all means knock yourself out!

    I was simply trying to convey that what you want to achieve is non-standard and likely can't be implemented using a QLineEdit. But don't take my word for it, go for it.

    Best of luck to you in your quest.
    I never said it's your responsibility, but your in your post you immediately claimed that the feature was useless. I can m like get the core functionality, but some of the extra features that I just posted on the forum are almost as important.
    But since you say. Its nonstandard, I'll seek out another solution. Thank you any ways.

  6. #6
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Changing color of SOME lineEdit / textEdit contents

    Quote Originally Posted by BeautiCode View Post
    I never said it's your responsibility, but your in your post you immediately claimed that the feature was useless.
    Perhaps useless was not the best choice of words, so I apologize for that. What you want to do is certainly non-standard and I do not know of a method to accomplish what you want, so unless someone posts a solution or an idea, I would not personally spend a lot of time trying to implement that.

  7. #7
    Join Date
    Mar 2015
    Posts
    24
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Changing color of SOME lineEdit / textEdit contents

    Quote Originally Posted by jthomps View Post
    Perhaps useless was not the best choice of words, so I apologize for that. What you want to do is certainly non-standard and I do not know of a method to accomplish what you want, so unless someone posts a solution or an idea, I would not personally spend a lot of time trying to implement that.
    Alright, it's no problem. Thank you!

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Changing color of SOME lineEdit / textEdit contents

    You would have to subclass QLineEdit and reimplement its paint event where you would have to paint the text yourself according to your needs. However be warned, here be dragons, this is not a trivial task.

    As for useless vs not useless, I've seen one (just one) situation where this was not useless. That was in SpeedCrunch calculator for highlighting parts of mathematical expressions on the fly. Nevertheless this was a very specific case.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Mar 2015
    Posts
    24
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Changing color of SOME lineEdit / textEdit contents

    Well since you guys keep thinking it's useless,
    It's for an IRC client. To distinguish chat messages that have pinged you from the other one, so when a user has the program minimized and hears the beep, it will highlight the message when they return.
    and if I had that ability, then I'd probably make the timestamp and usernames a different color too, to put some life into the program. But this is not as needed as much as the ping feature.

  10. #10
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Changing color of SOME lineEdit / textEdit contents

    What are you using for the widget that has all of the sent/received messages? If it's a read-only QTextEdit, it supports the concept of a QTextCursor and supports rich text format. It would be up to you, however, to program how you want lines, individual words, characters, etc to be formatted...

    How about posting some code to show what you are currently doing?

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Changing color of SOME lineEdit / textEdit contents

    Quote Originally Posted by BeautiCode View Post
    Well since you guys keep thinking it's useless,
    It's for an IRC client. To distinguish chat messages that have pinged you from the other one, so when a user has the program minimized and hears the beep, it will highlight the message when they return.
    and if I had that ability, then I'd probably make the timestamp and usernames a different color too, to put some life into the program. But this is not as needed as much as the ping feature.
    Seems like a job for QPlainTextEdit or QListView rather than QLineEdit.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 16th January 2014, 16:11
  2. Replies: 0
    Last Post: 3rd July 2013, 18:51
  3. Replies: 4
    Last Post: 8th September 2011, 08:22
  4. How to input Chinese characters in LineEdit or TextEdit ?
    By behlkush in forum Qt Programming
    Replies: 2
    Last Post: 23rd May 2011, 12:26
  5. How to store the lineedit contents in memory
    By grsandeep85 in forum Qt Programming
    Replies: 4
    Last Post: 3rd August 2009, 13:16

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.