Combine elided and word wrap on qt - c++

I am using a QLabel to show a text, and setting to word wrap property true, to show my text in lines when the size of the grid is smaller than the size of the text. But some words, when I define the minimum size to the grid, don't show all the letters.
Can I use Elided combined with word wrap property from QLabel?

Related

How to make fixed width of column with Helvetica font?

Usually, I use iomanip and setw to make a column with a fixed width for output.
But it seems to be that it doesn't work with Helvetica font.
What to do with it here?
Helvetica is a proportional font which means that the letters have different widths.
BTW, for most GUIs, you'll need something more specialized than std::cout.
In order to make a fixed width column you will need to pad to get to the next column. This means adding up the widths of the characters and the spacing. Subtract this from the column width and this becomes your padding.
Many GUIs have functions for determining the pixel widths of a string of text.
An easier route, IMHO, is to use a grid type widget in your GUI. These have column capabilities that can be adjusted. Some have functions that will resize a column based on its contents. You only need to put the text into that column.
Another GUI technique is to use vertical "boxes" (sizers) for each column. Place your text into the box. Let the box figure out its alignment and padding.

Using QTextEdit and html to display formatted log-text

I need to display a large (and increasing) log-file with QTextEdit (alternatively with QTextBrowser, must be one of those 2, though) and format the output in 3 columns with following properties:
1. column: text top-right aligned, fixed width, always 1 line (height depends on 2. column)
2. column: text left aligned, dynamic width (scales with window size), can be multiline with "wordbreak" (height depending on lines of text), can contain clickable URLs
3. column: text top-left aligned, fixed width, always 1 line (height depends on 2. column)
Is there somehow a way to use QTextEdit html markup (or something else, maybe) to achieve this and then simply append new log entries whenever necessary without recreating everything?
As a picture often says more than a thousand words I added an image of how I think it should look:

How to get correct position in the std::string?

I am creating a custom single line edit control, with a custom font in win32 api on windows 7, the font is not a fixed width font, and I need to move caret according to the mouse click, The edit control is not empty and if I know the horizontal position of the mouse click within the window, how do I calculate the number of characters after which I need to move caret to ?
I really am out of ideas, if it was a fixed width font, I would have divided the horizontal mouse click position with average character width, that would have been simpler, doing the same with not a fixed width font, is prone to errors.
Given that it's a single-line control, you probably don't plan on working with immensely long input (at least normally). That being the case, one possibility would be to just store the character positions in an array (or vector, etc.) Then you can use (for example) a binary search in that array to find character positions. Of course, you can do the same even for longer strings--though it can increase storage requirements quite a bit.
This is a familiar problem. You are in essence trying to do hit testing on text and for that you need the location on the screen of each character of the text.
My preferred strategy is to calculate an array of RECT, one for each character of displayed text. The array needs to be updated when text is added or deleted, but it easily handles single or multiple lines. The function GetCharWidth32 retrieves all the widths for a string of text in a particular font selected into a DC. For single line one call is enough, and calculating the array of RECTs is simple. It's not much harder to do multiline.
Handle the mouse down message, loop through the array and find the right character. A brute force search is plenty fast enough.
This method is simple and easily generalises to a range of similar problems.

Wrap text around the image

Can a list of Label objects and picture be aligned such a way that if the label has space in the right side it should make use of the full length before wrapping to the next line.
This is because of that fact that I may not have pictures of full height of the pane always.
For shorter images I want to make use of the space at the bottom.Note that the text is a nodelist of label nodes.

How do I set the number of visible lines in a Gtk::TextView?

I have a Gtk::TextView that I would always like to have two lines of text visible, regardless of the font size. Obviously if more than two lines were entered then the box would scroll but I'd like the text view to remain 2 lines tall.
How do I do this?
This is very difficult. For example, what will you do if two font sizes are mixed in one line?
One way to do it is to create a Pango layout of one letter and find out its height. This is an untested simplification of some code I wrote in C one time; but it shouldn't be too much trouble to convert it to C++ and GTKmm:
PangoLayout *cell = gtk_widget_create_pango_layout(textview, "X");
int line_height;
pango_layout_get_pixel_extents(cell, NULL, &line_height);
g_object_unref(cell);
gtk_widget_set_size_request(textview, -1, line_height);