qtooltip show sentence in single line qt - qt

showing a tooltip without any rich text in a single line works fine. But i have rich text in my tooltip.
QString tooltip="<span class=nobr>This is a much longer line than the first</span>";
which is getting displayed in 3 lines. How can i restrict it to 1 line. things i have tried
QString tooltip="<nobr>This is a much longer line than the first</nobr>";
QString tooltip="<span class=nobr>This is a much longer line than the first</span>";
QString tooltip="<span 'white-space:nowrap'>This is a much longer line than the first</span>";
How can i display a tooltip with rich text in single line
thanks in advance

The docs state:
Rich text displayed in a tool tip is implicitly word-wrapped unless specified differently with <p style='white-space:pre'>.
So something like this would work:
QString tooltip = "<p style='white-space:pre'>This is a much longer line than the first</p>";

Related

JavaFX Can't set any styles with Text node

I have a text field and I'm able to change the text size of a Text node no problem with
Text text = new Text();
text.setStyle("-fx-font-size: 16;");
but if I try to change the colour, nothing works:
textStart.setStyle("-fx-font-size: 16;-fx-color: #ff0000;-fx-text-base-color: #ff0000;-fx-text-fill: #ff0000;");
I find in JavaFX every node seems to need a different css command to successfully change the colour, but with Text, none of them seem to work. I can change the text with
text.setFill(Color.RED);
But it's awkward to have two separate commands on separate lines when it should be able to be done in one line of css. Especially since what I'm doing is relatively heavy processing of many lines of text.
Does anyone know what the css command to change the colour is with a Text node? Seems so odd it only accepts the size command in css..

QTextDocument Newline handling and eliding

I am using QTextdocument and in my text there are "\n" for new line characters but QTextDocument is not handling it and it shows it as plain 1 line .
Is there any way we can make it handle "\n" as new line character, along with that I need eliding also.
So whenever any text is there after line break it should show "..."
E.g. This
is
the
Sample
Currently QTextdocument removed line breaks and shows it as "This is the sample"
2nd issue is for eliding Now suppose only 1 line is visible it should show it as "This..."
How do I achieve this?
QTextDocument holds formatted text, so you can use <br> html tag for a new line and set it's content using QTextDocument::setHtml.
Also you cab use QTextDocument::setTextWidth to set a specific width for text in the document. If the content is wider, it is broken into multiple lines and grows vertically.
About eliding you can see this bug report which is unresolved.

Arabic/English text being shuffled

I have been stocked in a strange problem
I have a text box and i am trying to read the text. But when the text box contains both arabic and english text it seems that the text is shuffled . This is how i read my text from text box:
string temp = input.Text;
This is text that i am inserting in text box:
باهم and englishمتن فارسی
And this is the text that i get from textbox:
متن فارسی and english باهم
Add RLE char at the beginning of the text.
const char RightToLeftEmbedding = (char)0x202B;
Arabic is a right to left language. English is left to right. So that actually is correct- the arabic on screen will be in opposite order (string position 0 will be on the far right).
It's probably not a problem with ASP.NET, but with the HTML that it outputs.
Inspect the HTML elements in the browser and check the "direction" property in the computed style. If the main language of your input box is Arabic or Persian, it should be "rtl", and if it's English, then it should be "ltr". If it's the other way, you need to adjust it by using the appropriate dir attribute on the HTML elements.
This only adjusts it for the user interface. The text is probably saved into your database not with the correct direction, but that may be fine, because the database is internal and usually not seen by users.

Fitting the label text of tab widet Qt

I have a tab widget with two tabs in it in my Qt application. When I set the label text for a tab to a long word like 'Difference', some of the text goes out of the boundary of the tab and is not shown. How do I fix this so that the entire label text fits exactly in the tab?
Thanks,
Rakesh.
Qt receives that style from OS. By default on Windows text isn't truncated. You can set it manually using
QTabWidget::setElideMode( Qt::ElideNone );
I think elideMode would be helpful for you.
Try setting the value to Qt::ElideNone which will not show the ellipsis in the text, so I am guessing it might show the entire text.

QLabel: interlinea/linespacing in WordWrap mode

How do I set line height in QLabel when in WordWrap mode?
Use HTML text:
QString template = "<p style=\"line-height:%1%\">%2<p>";
QString targetText = template.arg(myPercentage).arg(myTex);
QLabel *l = new QLabel(targetText, this);
where myPercentage is like 60 - 80.
You will get condensed lines in the WordWrap mode
There is no line spacing property in QLabel. You can change the widget font, which will change the line's height, but I suspect that is not what you want.
Line height is computed from the QFont of the widget and can be obtained by the QFontMetrics associated with the widget. Using this information, you may create your own widget that has a line spacing property (and a text wrap mode), but that represents a lot of low-level work.
You can also edit the HTML of the QLabel directly in Qt Designer.
Select the label in Qt Designer.
In the Property Editor, under the QLabel section, select the text property and press the ... button.
Select the "source" tab and edit the HTML from there.
Here are two examples that control the line spacing of a QLabel using HTML (tested in Qt 5.7). I am sure there are many more (and some better) ways to write the HTML, but this should be a good start.
Example 1
<html><head/><body>
<p style="line-height:120"><span>
This is the first line of the label.<br>
This is the second line.<br>
This is the third and final line.
</span></p>
</body></html>
This example is neater if the line spacing is the same for the whole paragraph.
Example 2
<html><head/><body>
<p style="line-height:20"><span>This is the first line of the label.</span></p>
<p style="line-height:20"><span>This is the second line.</span></p>
<p style="line-height:100"><span>This is the third and final line.</span></p>
</body></html>
This example allows you to control the spacing of each line individually. I had to make the height of the last line 100 to prevent Qt from cutting it in half. I assume it affects how Qt calculates the height of the label as a widget.

Resources