PDA

View Full Version : Changing color of SOME lineEdit / textEdit contents



BeautiCode
28th March 2015, 02:33
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


Hello World, this is my program

to a lineEdit or textEdit, how do I change the "World," to blue and keep the rest black?

jefftee
28th March 2015, 02:43
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


Hello World, this is my program

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...

BeautiCode
28th March 2015, 02:56
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?

jefftee
28th March 2015, 03:16
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.

BeautiCode
28th March 2015, 03:27
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.

jefftee
28th March 2015, 03:32
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.

BeautiCode
28th March 2015, 06:42
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!

wysota
28th March 2015, 07:04
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.

BeautiCode
28th March 2015, 18:01
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.

jefftee
28th March 2015, 20:38
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?

wysota
29th March 2015, 23:49
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.