View previous topic :: View next topic |
Author |
Message |
jmaeding
Joined: 11 Apr 2008 Posts: 67
|
Posted: Wed Feb 23, 2011 6:09 pm Post subject: Alternate way to color text besides styles and richtext? |
|
|
I am trying to avoid richtext so I can compile x64, and trying to avoid extra row bindings just for the purpose of coloring text.
I do not really need the fanciness of richtext, just the coloring ability.
Can i override the paint event somehow to achieve coloring of text myself? I have not done that before so any help is appreciated.
Would it be easier to use cellwidget to derive my own control for this?
I am doing programmatic object binding. _________________ James M |
|
Back to top |
|
|
jmaeding
Joined: 11 Apr 2008 Posts: 67
|
Posted: Wed Feb 23, 2011 6:45 pm Post subject: |
|
|
I looked at the customcellwidget example a bit, but that uses a predefined blue style. I want to make the text several colors, so do not want a bunch or styles.
I would guess the paint event is what will be the answer. _________________ James M |
|
Back to top |
|
|
jmaeding
Joined: 11 Apr 2008 Posts: 67
|
Posted: Wed Feb 23, 2011 7:05 pm Post subject: |
|
|
read the help on deriving from cellwidget and overriding paint foreground, that seems like the answer, but it still uses a style.
How can I make that style be flexible? _________________ James M |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Feb 23, 2011 9:42 pm Post subject: |
|
|
The CellWidget.PaintText method is probably what you should override. It is passed the active style - but that doesn't mean you have to use the style colors if you don't want to. You can just use the Style.Font and draw the text yourself in whatever colors you want. _________________ Infralution Support |
|
Back to top |
|
|
jmaeding
Joined: 11 Apr 2008 Posts: 67
|
Posted: Mon Feb 28, 2011 5:04 pm Post subject: |
|
|
slick, I will try that, thx for response _________________ James M |
|
Back to top |
|
|
jmaeding
Joined: 11 Apr 2008 Posts: 67
|
Posted: Mon Feb 28, 2011 9:52 pm Post subject: |
|
|
I was able to colr the text with custom cellwidget whose creat method has a color parameter, to provide flexibility.
I am wondering though, how can I integrate this in with getcelldata, so I can be really specific on what cells to color what.
I know from other examples, i can set cell style in getcelldata, but what if i wanted to modify the cellwidget, such as changing its color property I added?
I ask because there are all kinds of things i might want to do to the cellwidget in getcellda, not just color. This would set the pattern of how to do that.
thx _________________ James M |
|
Back to top |
|
|
jmaeding
Joined: 11 Apr 2008 Posts: 67
|
Posted: Mon Feb 28, 2011 10:06 pm Post subject: |
|
|
I think see now, you can do it in the painttext code, using this.column, this.celldata and so on to do conditional things.
I'm still trying to figure out how to access the cellwidget from getcelldata though. Is that backwards?
also, when doing conditional things in the PaintText code for custom widget, I cannot check if the this.column == (some tree column name), as the tree columns are not available in its scop, but I can check the name:
if (this.Column.Name == "vtColName") {
I normally do this in getcelldata:
if (this.Column== vtColName) {
Is there a better way to test if the this.comun is the same as a given column in the tree, rather than a strings test, which will not give IDE error feedback if I rename some column. _________________ James M |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Mar 01, 2011 9:29 am Post subject: |
|
|
Quote: | I'm still trying to figure out how to access the cellwidget from getcelldata though. Is that backwards? |
That is backwards. The cell widget draws itself based on the data in CellData. If you want to extend the CellData properties you can override the VirtualTree.CreateCellData and return a derived class that has additional properties. Your GetCellData method and custom cellwidget code can cast to the derived CellData class and access those additional properties.
Quote: | Is there a better way to test if the this.comun is the same as a given column in the tree, rather than a strings test, which will not give IDE error feedback if I rename some column. |
Normally I would try to make the code more data driven if possible - so adding properties to CellData as discussed above to determine rather then hardcoding based on specific columns might be better. If you are going to base formatting on the column then the only way I could see to avoid the string comparison would be to add some Column properties to the derived VirtualTree class which you could set to specific columns. Then your custom cell widget could check whether they match those columns. _________________ Infralution Support |
|
Back to top |
|
|
|