Adding Basic Text to Win32 App, c++ - c++

So i am making a tic tac toe game (I am a just barely beginning, and this is my first ever attempt to do anything windows), and i want to have a section where the game can keep score. I can't figure out how to add simple text to the window, like the word "SCORE" so i can put the score underneath it in a fancy little table. I have figured out how to make a text window using the following code:
CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT("PLAYER 1"), WS_CHILD|WS_VISIBLE, 20,250,100,25,hWnd,HMENU(NULL),GetModuleHandle(NULL), NULL);
CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT("PLAYER 2"), WS_CHILD|WS_VISIBLE, 130,250,100,25,hWnd,HMENU(NULL),GetModuleHandle(NULL), NULL);
That is useful to me for the names because the players can go in and edit the text boxes to put in their own names (if there is a better way to do this i would appreciate any tips here too). But really my question is can i make a window like this to display text that CAN'T be edited by the user?

The "EDIT" class name is for edit controls. You're looking for more of a label, and that is offered through the "STATIC" class name, along with support for an icon or bitmap rather than text.
As for the later question of how to centre it, it's one of the many static-control-specific styles you can use. The one in particular you're looking for is SS_CENTER, which can be bitwise-ORed with your two WS_* styles.

Related

Make a QDialog read only, but still with text selectable

Disclaimer: I'm not a Qt programmer, I'm just asking in case someone could solve an issue about DB Browser for SQLite.
So, an EditDialog widget is extending the QDialog class. As described in the issue, in some scenarios this widget is readonly, but it would be great if its text content could still be selectable.
There are two use cases:
text selection with the mouse
blinking caret, text selection with keyboard Shift + arrows
The current solution fixes only the first case. There is no blinking caret and keyboard selection doesn't work. Could this be improved?
Assuming the textarea is a QTextEdit or QPlainTextEdit, you should be able to fix this by adjusting the text interaction flags. Try something like this:
ui->editorText->setTextInteractionFlags(
Qt.TextSelectableByMouse | Qt.TextSelectableByKeyboard)

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.

How to create a basic GUI(storing names and addresses in a list) using Qt?

http://www.youtube.com/watch?v=r57rO3p1Bcs&feature=youtu.be
So what im trying to do is recreate the gui in the posted video. I have the main window created, and the dialog window. Im brand new to Qt and I have been going over tutorials for all the basics. What I havent been able to find much on is how to go about storing the three values from the "new student" dialog window into the list and how to display the first and last name. I'm also not too sure on how to go about making the values editable.
This is NOT an assignment for any sort of class. I'm trying to learn for my own purposes.
Any sort of strategy for how to link the values from the dialog window to the list, and from the list to main window line edits would be very helpful to me.
A good place to start is the Qt's Model/View introduction.
LE: for a simple way to start look at QListWidget class

Remove the "Customize Quick Access Toolbar" button

I'm working on a project where we want to have a quick access bar that is unchangeable/static. We've looked at inheriting from the CMFCQuickAccessToolbar and removing that button, but those attempts seem fruitless. Just getting rid of the button completely gets rid of the toolbar. Anyone have some experience with this, or an alternative approach?
After a lot of headache we found that there was no clean solution to removing just that button from the toolbar. Instead, we opted to place the buttons we wanted to display in the quickaccess bar in the tabs group. These button will appear on the right side (beside the help icon in word). To replicate the look of the QA buttons, I had to create an imagelist and load our buttons into it.
CImageList theList;
CBitmap bm;
bm.LoadBitmap( IDB_QASMALL );
theList.Create(16,16, ILC_COLOR32 | ILC_MASK, 5, 0);
theList.Add(&bm, RGB(192,192,192));
I then created ribbonButtons to be added to the tabs group, with the proper command IDs, empty text, and the proper icon from my image list.
CMFCRibbonButton* button = new CMFCRibbonButton( ID_SOMECOMMAND, _T("\na"), theList.ExtractIcon(<IconOffset>));
m_wndRibbonBar.AddToTabs(mp);
It's not a perfect solution, but it at least gives us a similar UI without the worry of getting rid of that stupid customize button. You also have the freedom to use labels on your buttons.