Multi-line control in VCL forms - c++

I am using C++ Builder to create a VCL forms application and am wanting a multiline editbox.
Am I correct in saying that I have to use a TRichEdit control to accomplish this?
If so, (and I have added one just to try out), how do I set the text in the control? There seems to be no .text or .caption property.
I can get the contents of the TRichEdit by the ->text property, but how do I 'set' the text?
Thanks

The Text property is read/write:
String s = RichEdit1->Text;
RichEdit1->Text = ...;
It is just declared as __published so you will not see it in the Object Inspector at design time. If you want to see the text at design time, you have to use the Lines property instead.
BTW, TRichEdit is not the only multi-line edit control. TMemo is another one. The main difference between them is that TRichEdit supports more formatting options than TMemo does. Think of them as the VCL equivalents of the MSWord and Notepad apps, respectively.

Related

QTextEdit: typing in HTML/richttext

I have a QTextEdit and want the user to be able to type rich text which will then automatically be (correctly) shown in the widget (so: formatted).
It works fine when setting the text programmatically (using setText()), but not when manually typed. See picture below.. "Input" is set using setText, the following line is manually typed. I would like this line to automatically be formatted a
What's the (easiest) way to do this? The only way I can think about it to manually catch key events and explicitly set the text as HTML.. But I'm sure there's a better way.
Manual typed html gets escaped, the < will become a < etc . .
You wouldn't be able to edit it if that would not be the case, for obvious reasons.
You could try adding a [render] button or something like that to render the entered text to html. Trying to render on keypress is very dangerous because it makes it terribly inconvenient and counter-intuitive to type something and then have it magically change the output. Also un-finished markup will probably throw a stick in your wheel.
Also pasting from a rich text source (for example a webpage) keeps the formatting.
As "the JinX" already said it will not be so intuitive if you try to capture every key event and then try to change the text to render in HTML.
Though you can use some special key sequences, say "shift+return key" to change the text of current line/entire textedit to to html formatted one.
This is just a suggestion.
In this case more than implementation it is also about what a user will expect.
Changing the text of 1 line/entire textedit from plain to HTML would be easy to achieve as well.

Hide label text for Qt tabs without setting text to empty string

I need a QTabWidget with icons only:
How can I hide the label text of a tab in Qt? I cannot set the text to an empty string (""), as I am using docked widgets ( QDockWidget ) and the label text is set automatically (and I need it if the widget is floating).
But in tabbed mode I just want to display the icons (of the tabs).
Possible approaches:
Font size to 0?
I need to create my own bar class and override the paint event as here
Anything easier / cleaner?
--- Edit ---
Ok, the "set window title to empty string, and reset it the original text" approach works. I am using the topLevelChanged signal for this. However, it has some drawbacks, as the empty text still occupies some space. Another issue, with the text the tooltip is gone, and I cannot set it back.
What I am currently trying is something in-between the "text empty" and Prasad Silva's approach. I try to identify the text label inside the tab and set its size to 0, then reset it. It's slightly different, but would keep the text intact.
Btw, I see a line on top of my tabs, any idea what this is (where it comes from)?
Edit: There seems to be no "easy way" (style sheet, attribute) for this, see Hiding bottom line in QTabBar
Maybe I will create the whole tab bar on my own, as the automatically generated stuff is just too hard to handle (agree with PS on this).
This can not be done easily. Use empty text.
The way I solved something like was to create a QDockWidget subclass that installed a QWidget subclass as the titlebar (via setTitleBarWidget). This gave me control over showing/hiding the text in the titlebar when the dock widget fires topLevelChanged, dockLocationChanged and visiblityChanged.
This is really a big hack to get around the fact that Qt has refused to expose a public API for the docking system. We have since moved on to a custom docking implementation due to these limitations.
If you do not want to see the text, you can set it to an empty text after saving the current text, and when you want to see it again, restore it from the stored variable.
I do not think there is anything in the API for this not so common case, which means you will need to do it yourself.
Now, you could claim that it is tedious to do for many widgets, but on the other hand, you could write a simple hash define or inline function to do this repetitive work for you, which would only result a one-liner call, basically, which you would need to use anyway when changing the state.

Using different fonts/attributes in QTextEdit

I have a problem with displaying a text to area with different attributes.
My project has a multi-threading build. I reach to GUI text area by using signal-slot mechanism. I put my texts to the text area like this;
addrMW->ui->printerArea->appendPlainText(command.Data);
I want to append my text to this area with different font, size, etc..
I'm using Qt Creator 2.7.2 / Qt 5.1. Could someone explain this to me with an example?
What you want is a rich text edit. Luckily QTextEdit is able to handle that. Check the acceptRichText property (which should be true by default).
Then the methods you're looking for are:
setCurrentCharFormat
setCurrentFont
setFontFamily
setFontPointSize
etc...
Then, instead of appendPlainText() you should use append() to add text to the QTextEdit. Also see this Q/A. As proposed in the accepted answer, you can also use html formatted text instead.

Paste multi-line text into single-line Edit Box control

My app uses standard single-line Edit Box controls. Is there any way to accept a multi-line "paste", discarding carriage return / linefeeds?
Notes
I don't want to use multi-line controls
My app is VS2010 C++ with WTL (not MFC or ATL)
The reason I want this is because actual input is normally quite short, but could in rare circumstances be hundreds or even thousands of characters. In which case users might well want to build the string using NotePad or whatever, then just cut & paste it in.
This is not possible as the user is pasting himself/herself. An alternative is to use a multi-line Edit Box and displaying all the data into one line by managing the pasted data into OnChange function for your control (basically disregading new lines).

Using richtext in QTextEdit

What is exactly richtext and how do I format data in richtext in QTextEdit?
The internal rich text format is tag/attribute-based, and is similar to HTML using in-line CSS style="xxx" attributes. The default export/import format (using toHTML/setHTML) is a subset of HTML. See this link:
http://doc.trolltech.com/4.6/richtext-html-subset.html
Note that CSS classes are not supported internally and are converted to their representing attributes at import.
QTextEdit can display text that is formatted with additional layout and style information (i.e. enriched) which can be set either programatically or by using a subset of HTML.
The Rich Text Processing documentation gives you an overview and pointers to more in-depth information.
If you're looking for a WYSIWYG toolbar for the QTextEdit, you'll end up disappointed. There is no default one (although the SDK contains an example app). So you should either make the toolbar yourself or find one.