Page 1 of 1

Foreground of qt5.textedit.

Posted: Friday 10th June 2022 4:32pm
by seany

I am trying to work with a q5 textedit. The one highlighted in picture:


I have the following code:

Code: Select all

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

I expect it to be triggered when the form is loaded, as resize is called in the beginning. Everything works, but

Code: Select all

TextEdit1.Foreground = Color.Red
The result is:


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.

Re: Foreground of qt5.textedit.

Posted: Saturday 11th June 2022 11:30am
by BruceSteers
It's RichText so it's HTML based.
the Foreground does not seem to do anything.

But code like this will work.....

Public Sub ToolButton1_Click()

   TextEdit1.RichText = ("New String <font color=red>This is a red part </font> and this is not")

RichText is not full HTML only basic.
Setting TextEdit1.Text or using TextEdit1.Insert() will also not work for colors , use TextEdit.RichText

Re: Foreground of qt5.textedit.

Posted: Saturday 11th June 2022 1:00pm
by cogier
Tip: - use the gb button for better code display.

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: -
(12.22 KiB) Downloaded 9 times
You might like to have a look at how to create expanding forms in Gambas here.

Re: Foreground of qt5.textedit.

Posted: Saturday 11th June 2022 1:54pm
by seany
Thank you

Re: Foreground of qt5.textedit.

Posted: Sunday 12th June 2022 1:46pm
by BruceSteers

See my post here Seany


I discovered the TextEdit1.Selection.RichText property that would be like having a TextEdit1.InsertRichText() method to insert html code at the cursor position.

I found you can not just insert unfilled html code for example..
TextEdit1.Selection.RichText = "<font color=red></font>"
Because there is no text to show just the code.

Using this code however in the KeyPress handler...
TextEdit1.Selection.RichText = "<font color=red>" & Key.Text & "</font>"
Stop Event
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

Re: Foreground of qt5.textedit.

Posted: Tuesday 21st June 2022 7:49pm
by BruceSteers
I just discovered another magic property TextEdit1.Format ... dit.format

Thanks to James on the gambas mailing list ... 76305.html

With that you can quickly get or set various things at current cursor position or for selected text, very handy.
Has the following properties...
  • Alignment
  • Background
  • Color
  • Font