Foreground of qt5.textedit.
Posted
#1
(In Topic #858)
Regular

I am trying to work with a q5 textedit. The one highlighted in picture:
<IMG src="https://i.imgur.com/qWoHctI.png">
</IMG>I have the following code:
Code
Public Sub Form_Resize()
ToolBar1.Width = Me.W
TextEdit1.W = Me.W / 2 - 10
TextEdit1.Background = Color.RGB(190, 190, 190)
TextEdit1.Top = ToolBar1.H + 10
TextEdit1.Height = Me.H - 10 - TextEdit1.Top - 50
TextEdit1.Foreground = Color.Red
End
I expect it to be triggered when the form is loaded, as resize is called in the beginning. Everything works, but
Code
TextEdit1.Foreground = Color.RedThe result is:
<IMG src="https://i.imgur.com/PnohMxw.png">
</IMG>As you can see, the foreground color did not take effect.
I am on Artix Linux, KDE. Output of uname -a :
Linux glassplanet 5.17.4-artix1-1 #1 SMP PREEMPT Thu, 21 Apr 2022 06:59:38 +0000 x86_64 GNU/Linux
I attach the project. what can I do so that the color will take effect? Thank you.
Posted
Guru

the Foreground does not seem to do anything.
But code like this will work…..
Notes:
RichText is not full HTML only basic.
Setting TextEdit1.Text or using TextEdit1.Insert() will also not work for colors , use TextEdit.RichText
Posted
Guru

<IMG src="https://www.cogier.com/gambas/gb_button.png">
</IMG>I discovered that Background does not work, but a workaround is to place the TextEdit in a Panel then you can change the background of the panel.
To change the font you need, as Bruce says, to use Richtext.
Have a look at the code in the attached program: -
<IMG src="https://www.cogier.com/gambas/TextEdit.png">
</IMG>You might like to have a look at how to create expanding forms in Gambas here.
Posted
Regular

Thank you
Posted
Guru

See my post here Seany
Gambas One - Gambas ONE
I discovered the TextEdit1.Selection.RichText property that would be like having a TextEdit1.InsertRichText() method to insert html code at the cursor position.
PS.
I found you can not just insert unfilled html code for example..
Code (gambas)
- TextEdit1.Selection.RichText = "<font color=red></font>"
Using this code however in the KeyPress handler…
will work just fine and the cursor is inside the font definition so more text added at that place will be the same color
Best of luck
Bruce
Posted
Guru

Thanks to James on the gambas mailing list [Gambas-user] TextEdit as RichText Editor
With that you can quickly get or set various things at current cursor position or for selected text, very handy.
Has the following properties…
<LIST>
- <LI>
- Alignment</LI>
<LI> - Background</LI>
<LI> - Color</LI>
<LI> - Font</LI>
Posted
Regular

1 guest and 0 members have just viewed this.


