QListWidget very long text - c++

I'm asking this question because i dont know how to google it, i dont find the right keywords.
I have a QListWidget with strings inside. The strings are very long and if i disable horizontal scrolling, which is what i want, then the text ends with ... because it is too long.
I would like to have the text to display the end of the text and the beginning like:
This is very long text to This is ... text instead of This is very long ...
Is there any simple way to achieve this without having to manipulate the string? I need the full string afterwards and i dont want to store extra data. Any help is appreciated.

There is indeed a very easy solution: Lock for TextElideMode and Qt::ElideMiddle (setTextElideMode ( Qt::TextElideMode mode )).

Related

Reduce String to visible/readable text only (C++, Qt)

Hej Folks.
I cannot find an answer for my question, so apologize if that's a duplication.
I have a Qt Application and running a Qt::Process.
Furthermore, I show the stdout and stderr of the process to the user, so errors can be understood.
My approach is to append every output to a QString I can show in a Text QML Type.
QObject::connect(update, &QProcess::readyRead, [update, this] () {
QString newline = QString(update->readAll());
m_updateLog.append(newline);
emit newUpdateLog();
});
The problem is that with a lot of \r (Carriage Return), the QString quickly gets pretty long.
I hoped to somehow reduce the length of the QString to his "readable" length?
Example : QString("Hello\nWorld\rUniverse") becomes QString("Hello\nUniverse")
I tried to write my own logic … but I'm kinda too stupid that it's work properly.
In the future I will cut the QString to a max length, but in cases with a lot of CR it gets kinda ugly,
because important informations will be cut :/.
( Example: QString("Loaded:\n0.4%\r0.5%\r0.6%\r0.7%\r0.8%\r0.9%\r1.0%") )
Thanks for any help.
I wouldn't expect there to be any magic that understands that stuff before a "\r" is effectively erased -- that logic is in the text rendering implementation not any string formatting. You would have to implement it yourself; you would have to track where the "\r" is backing up the cursor to.
I would suggest replacing your single string (whatever type m_updateLog is) with a list or array of strings, with each line of output (delimited by "\r" or "\n") as its own string. That way when you see a "\r" you can drop the last element. Also if the array gets too long, you can remove the first elements to shorten it, so that you have a kind of rolling tail of the output.

Is there a SwiftUI equivalent for lineBreakMode for Text views?

I have a Text view, and I would like to configure it to wrap the first character that doesn't fit. In UIKit, this would be the equivalent of setting label.lineBreakMode = .byCharWrapping. Has this been implemented for SwiftUI Text yet? I haven't been able to find anything in the documentation for Text.
The reason that I want to do this is that I'm displaying a long code to the user, so wrapping by character rather than by word is desirable.
Not sure if this helps, but I am using the following which leads to long words getting wrapped by characters:
Text("Supercallifragilisticexpialidocious")
.font(.system(size: 100))
.minimumScaleFactor(0.01)
.lineLimit(3)
.multilineTextAlignment(.leading)
Unfortunately for my use case, I do not want the Text to wrap by characters. If I set lineLimit(1) that works fine and the font size is reduced to keep the Text on 1 line. But if Text is multiple words such as Text("Practically perfect in every way") then I want the string wrapped by word. I can't seem to get both Word wrapping for multiple words and font scaling for long words.

QPushButton tooltips inserts a line break without me specifying it

I have code like this:
//QPushButton*
myButton->setToolTip("ReallyLong String lolol<br>shortString");
And what happens is that sometimes, when I have a long and a short string, the long string gets cut off at some point and continues on the next line,so I end up with 3 lines, something like this:
ReallyLong String lolol shortString
Why is this happening? There doesn't seem to be a way to control it.
Why is this happening? There doesn't seem to be a way to control it.
From the QToolTip man page:
Rich text displayed in a tool tip is implicitly word-wrapped unless
specified differently with <p style='white-space:pre'>.

Visual Studio C++ removing last character from string

I need a little help with my calculator program. I have created the code for the main buttons like the numbers 0-9 and the arithmetic operators to make it perform simple calculations.
What I'm having problems with right now is making the CE button work, after clicking the CE button I need the last entered character to be removed from the display label.
I have tried to adapt this code somehow, but it doesn't work:
lblResult->substr(0, lblResult->size()-1);
I know I'm doing somehting wrong here, can you please help me?
Thanks in advance
...Now that we know that lblResult is a System.Windows.Forms.Label, we can look at the documentation.
A Label has a Text Property, which is a String^ (i.e. a string reference).
For what you want to do, the Remove Method of String is appropriate. But note in the documentation it says that it "Returns a new string in which a specified number of characters from the current string are deleted." This means that it does not modify the string, but returns a modified copy.
So to change the label's text, we need to assign to its Text property what we want: the current string with all of the characters except the last:
lblResult->Text = lblResult->Text->Remove(lblResult->Text->Length - 1);
lblResult->resize(lblResult->size() - 1);
In this case you can use components Remove and Length methods.
Use the following code to access the components text:
component->Text
Than remove the last character of string by accessing Remove and component Length method
= component->Text->Remove(component->Text->Length - 1)
I hope you find this useful.
Just asking the obvious -- the whole statement is
*lblResult = lblResult->substr(0, lblResult->size()-1);
right?

c++ create text fits edit box

Well.. I know that title is not that clear, I couldn't think of better one.
I wanna know how to do this...
when you have edit box and it only can show 10 characters.
Something like this
ssssssssss
let just say i have more than 10 characters. Some of them will go in the back.
Like we have this string "123456789010" it will show just these ones "3456789010".
My problem is that some characters are small and don't take that much space and some do.
So i can't find a way to break the string and get some characters in the back.
any idea?
Try this in Style type in edit box use ES_MULTILINE for use multiple lines.
edit1=CreateWindowA("edit","edit box",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE,120,160,200,200,hWnd,(HMENU)IDI_EDIT,hInstance,0);
You can calculate the display-length of the string in your control (there are several function for that) and adjust the size of the control accordingly.
you only want to see the far left or far right?
here is your string "0123456789"
you can only display 5 values due to pixel size of box....
do you want it to be "...56789" more like "56789"
or "01234..." more like "01234"?