How can I set word wrapping in QToolButton's text? - qt

I want to show some text in a QToolButton derived class but it needs to be word wrapped. I would like to do it in an "automatic" way (instead of using \n when needed) just as one can do it when using QLabel and setting word wrapp to true, but I couldn't find anything on Qt Assistant that would do that for me.
So, is it possible? And how is it done? If there is nothing like word wrapping for QToolButton, how could I get around this without using "hard code layout" (that is, \n)?

Related

Can I add a css style in the formula editor in crystal report

In crystal report:
right click on a field -> edit formula. I can add some html elements.
example
<u>
IF {myobject.myfield} = "something" THEN
blabla1
ELSE
blabla2
</u>
Is there a way to add a css font style?
I would like to underline the whole line. Not only where there is text
You can use something like this:
IF {myobject.myfield} = "something" THEN
<u>blabla1</u>
ELSE
</u>blabla2</u>
But that would require turning on the 'Interpret as HTML option.
Why not simply format the formula object with underline?
Even with a CSS style, it will still only underline the text and will not extend the underline beyond.
I see two other ways to accomplish this though.
Make the field the entire width of the area that you want to be underlined, then add a bottom border to the field or text object.
Use the line drawing tool to add a horizontal line to the report where it is needed.
It doesn't give a solution to the mentioned problem. But it give a solution to the problem that leads to this problem, i.e., underline the whole line.
select the feld, click on underline. In "edit formula", add space(N) before each line break. With N is a big number

How to add a default Text at the start of the multiline React Native TextInput

I'm trying to implement the replying input in React Native and I'd like to have a possibility to render the person name I want to reply to at the start of my reply text. I attached the example image. This Input will be multiline and it's important because I was thinking about adding some padding for my reply TextInput and just absolutely position the Person Name text at the padded space.
It looks like a possible solution but:
How to do it if we have multiline Text? if we add some padding for the TextInput it will affect all lines when I need only the first one
The person name text could have various width so the padding value shouldn't be hardcoded. I think it could be solved by just rendering the Person name text first, calculating its width, and the set the padding for the TextInput but even in this case we'll face the issue 1)
Is it possible to achieve this feature somehow?
Thanks for any help!
You could have a nested style.
<Text style={styles.username}>#Rosemary#9234<Text style={styles.body}>I agree with you!</Text></Text>

QML TextArea colored text with selection

i am trying to accomplish the following behavior with a QML TextArea:
I want single Words in the Text to be colored differently
I want the "select"-functions to be working for automated scrolling (user interaction is disabled)
There is a stream of text in the TextArea where one Word needs to be selected(highlighted). The user is requested to input some text elsewhere and press enter to proceed (not part of the question). After that the selection jumps to the next word and the last selected word is either colored green or red. There is only a small portion of the text visible (a few lines, managed by the TextArea height – not part of the question) and i need the text to scroll if the next word is out of that visible range .. therefore the selection is quite helpful because all interaction from the user – to scroll or select or whatever – is disabled (disabling is not part of the question)
my main problem is: if i use textFormat: TextEdit.RichText i can easily color the text how i like it to be (<font color=\"green\">{}</font>) but i cannot use the "select"-functions anymore because – as i would guess – the selection works on the "plaintext" and cannot correspond to the "richtext"-selection? Anyway selectWord() etc. does not work QTextCursor::setPosition: Position '-1' out of range is the result. But if i disable the RichText i don't know how to color the text. Maybe i could live without the selection if i could detect the current word – which would be colored blue etc. – and scroll if its out of the visible area to "fake" the selection behavior, but that's just a third option.
I would really either know how to color non-Rich Text or how to select Rich Text in a TextArea.
You can use QSyntaxHighlighter to highlight the words independent of the selection. See QQuickTextDocument and How to implement rich text logic on QML TextEdit with QSyntaxHighlighter class in Qt for more details.

QLabel auto multiple lines

For example, we have a QLabel with MaximumWidth set to 400.
When we try to display some text with pixel width more than 400, it's shown cut off.
Is there any way to make QLabel display this string in multiple lines without using QFontMetrics or the like?
If I understood your question correctly, you should use the setWordWrap function for your label, with true as its parameter.
QLabel lbl("long long string");
lbl.setWordWrap(true);
In order to show multiple lines in QLabel, right click on QLabel and select 'change rich text'. This brings up dialog where you can type the text as you want to see including enter key. Setting the word wrap is not required for this.
If you set the word wrap as well (in QLabel properties) than it will wrap each individual line in the Qlabel if it was longer than the real estate.
As another option to wrap text using Qt Designer, you can check the box under Property Editor for a QLabel:

Hiding text with QSyntaxHighlighter

Problem: I want to implement a text editing widget for text with additional tags.
I'd like some tags to be invisible in some cases so that they do not distract the user.
Environment: I'm using PyQt and prefer to use QPlainTextWidget and QSyntaxHighlighter.
Approach: With QSyntaxHighlighter I can set QTextCharFormat for the strings which match my requirement. QTextCharFormat has gives me all font properties like size, colors, etc. but: I haven't found a option to hide the text or reduce its size to zero.
I don't want to remove or replace the tags, as this will introduce a lot more code (copying should contain tags and without I can't use QSyntaxHighlighter for formating the remaining text according to the tags).
Update: So far I found a ugly hack. By setting the QTextFormat::FontLetterSpacing to a small value, the text will consume less and less space. In combination with a transparent color the text is something like invisible.
Problem: In my test this worked only for letter spacings down to 0.016 %. Below the spacing is reseted to 100 %.
You can use the underlying QTextDocument for this. It consists of blocks whose visibility can be turned on and off using setVisible. Use a QTextCursor to insert the text and new blocks and switch visibility. As a bonus the copy function copies the content of non-visible blocks anyway.
Notes: See the documentation of QTextCursor for more information. In another question here is was reported that setting the visibility is not working on QTextEdits.
Example:
from PyQt5 import QtWidgets, QtGui
app = QtWidgets.QApplication([])
w = QtWidgets.QPlainTextEdit()
w.show()
t = QtGui.QTextCursor(w.document())
t.insertText('plain text')
t.insertBlock()
t.insertText('tags, tags, tags')
t.block().setVisible(False)
print(w.document().toPlainText())
app.exec_()

Resources