Foreground of qt5.textedit.

Post

Posted
Rating:
#1 (In Topic #858)
Regular
seany is in the usergroup ‘Regular’
Hello

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

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

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#2
Banned
It's RichText so it's HTML based.
the Foreground does not seem to do anything.

But code like this will work…..

Code (gambas)

  1.  
  2. Public Sub ToolButton1_Click()
  3.  
  4.    TextEdit1.RichText = ("New String <font color=red>This is a red part </font> and this is not")
  5.  
  6.  
  7.  

Notes:
RichText is not full HTML only basic.
Setting TextEdit1.Text or using TextEdit1.Insert() will also not work for colors , use TextEdit.RichText
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
cogier is in the usergroup ‘GambOS Contributor’
Tip: - use the gb button for better code display.
<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>

Attachment

You might like to have a look at how to create expanding forms in Gambas here.
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
seany is in the usergroup ‘Regular’
 Excellent.
Thank you
Online now: No Back to the top

Post

Posted
Rating:
#5
Banned
.

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)

  1. TextEdit1.Selection.RichText = "<font color=red></font>"
  2.  
Because there is no text to show just the code.

Using this code however in the KeyPress handler…

Code (gambas)

  1. TextEdit1.Selection.RichText = "<font color=red>" & Key.Text & "</font>"
  2.  

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
Online now: No Back to the top

Post

Posted
Rating:
#6
Banned
I just discovered another magic property TextEdit1.Format  /comp/gb.qt4.ext/.textedit.format - Gambas Documentation

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>
</LIST>
Online now: No Back to the top

Post

Posted
Rating:
#7
Regular
seany is in the usergroup ‘Regular’
This is very nice, thank you
Online now: No Back to the top
1 guest and 0 members have just viewed this.