displaying ellipsis in CEdit control - c++

I'm surprised that i haven't found much online concerning the display of ellipsis in a CEdit control in MFC. We have a control that can show only about 20 characters but the max length of the string that goes into the control is 32 characters. I am interested in showing a middle or end ellipsis if the string length goes beyond the visible length. Has anyone tried this? Something that concerns me is whether the string pulled out of that control using GetWindowText will return the actual string or the string with the displayed ellipsis?

CEdit displays the window text. If you want to change the display, change the text.
You can change the window text to something more readable when the edit loses focus, and restore the original text when the window gain focus again. Also adjust your GetWindowText calls to read from a variable instead of a window.

Related

Remove the limit on the number of characters that can be entered into a Win32 Edit control

I've searched everywhere and it seems I can't find a solution to this problem..
My problem isn't limiting the amount of characters that can be entered into an edit control, my problem is I am limited by the size of the edit control. I want to be able to type past the size of the edit control.
I've tried extending the character limit to a high number with SendMessage and sending EM_LIMITTEXT, but that only seems to work if I want to limit it even more.
Here's an image example of my problem:
I use CreateWindowEx to create the edit control, but there doesn't seem to be an extended window style OR an edit control style that achieves what I want.
The style you're looking for is ES_AUTOHSCROLL. Without this style, input cannot go past the length of the edit control. With this style, text is automatically scrolled to the right by 10 characters when the input reaches the end of the control.
You may also be interested in ES_MULTILINE, which does exactly what it says. The default (without this style) is a single-line edit control.
All of the available styles are documented here. These are just regular window styles, not extended ones.
Also, I am pretty sure that you cannot change these styles at runtime, after the control has been created. Therefore, make sure that they are specified when you call CreateWindowEx, or in your resource file if the control lives on a dialog.

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.

Display tooltip for a selected word

I'm writing a simple text editor using Python 2.7, pyqt library. I basically want to display the meaning of a word when the user selects the word in the text editor.
So far I can detect the word under the cursor, look it up in my dictionary and return the meaning (using a print statement) so I know I can get the guts to work.
My trouble is displaying the meaning of the word in a tooltip that doesn't dissapear in less than 2 miliseconds. So far I have been using this:
QtGui.QToolTip.showText(QtGui.QCursor.pos(), tool_tip_text)
Ideally want to show the meaning just over where the selection was made, so far this displays the tooltip so quickly that I can't even read the meaning of the word under the cursor. It just pops up and dissapears almost immediately. Can anyone share how to make the tooltip remain visible for at least 5 seconds, or until the user de-selects the word.
I am not using the QHELPEVENT (not even quite sure how the helpevent is triggered) I am just calling my lookup_word_in_dictionary() function when a word has been selected.
Any samples are much appreciated.
Thanks, I found a solution, creating my own popup class, subclassed from QWidget
and used a simple timer to hide the tooltip
QTimer.singleShot(5000, self.hide_tooltip) #check to see if the tooltip shold be hidden after 5 secs
you can replace QToolTip by QSplashScreen,if you are Chinese ,please look at this post .
BTW , can you share the method that you detect the word under the cursor with me ?

How to determine the font of a QTextBlock

Let's say a user pastes some random text into a QTextEdit. How do you determine which font that text is in. For example, Chinese.
I've tried getting the QTextCharFormat for the block. But it seems to be empty of information.
Querying for fontFamily() gets me an empty string.
I've also tried to use the QTextLayout - but that seems to get me the default layout for the document, not for the specific text block.
Thanks for any pointers.
It seems you have to go to iterate over the QTextFragment's inside your block.
The fragments are what contain the specific font information.

Ellipsis do not work for static text in ATL project

I am currently working on an ATL project with a simple UI.
In this UI I have a couple of static text controls and I want them to have ellipsis at the end when the text is to long. So I set the word ellipsis property in the designer to true (which also triggers end ellipsis and path ellipsis to true).
However during run-time there are no ellipsis, instead the text is only clipped to the size of the static text control.
I also retrieved the style flags of the control (via GetWindowInfo(...)) and the bits for the ellipsis are set right, so I think it is some kind of drawing problem.
edit: I found out that the ellipsis work perfectly fine when I enter some long text in the Designer under "caption" and do not change the control. However when I try to set a new text via SetDlgItemText or .SetWindowText no ellipsis appear and the text that exceeds the bounds is just clipped.
As an update, I found out why it does not work. Seems that the ellipsis do not appear when I use tabstops in my text...
Any ideas on this one?
Check if your static is set to single line. IIRC the ellipsis only work for single line statics.