So I'm working on a class project that uses MFC. I never had to learn how to work with MFC since I was making the character class stuff (D&D game).
I currently have the radio buttons working. So I know which was pressed and can retrieve it.
My problem is this: I have 2 radio buttons, which represent the 2 sets of 6 dice rolls to be used for stats.
I want to display a string containing the set for the specific radio button. So what I'm wondering is: is there a way to have the caption string for a radio button be equal to a specific string that can change between the times the dialog with said radio button is opened?
Edit: I changed the whole question since I solved all but this part of the original.
MFC wraps radio buttons in CButton instances, so you can use their SetWindowText() method:
yourRadioButton.SetWindowText(_T("New Text"));
Related
I'm looking for a way of nesting comboboxes in my GUI application (or to be more precise, I'm looking for a way to have an item displaying similar visual and functionnal properties as nested comboboxes).
Looking first at all the functions provided by the combobox class, it seems comboboxes nesting it's not supported by Qt.
I therefore thought that another solution would be to create a "menu" item outside the menu bar. If I understand correctly this phrase from the offical Qt documentation, it seems to be feasiable :
A menu widget can be either a pull-down menu in a menu bar or a standalone context menu
Not sure though was is meant by the "context" word.
However, there is no such (menu) widget in Qt designer and I haven't found any good examples about how to do it on the internet (and can't get a menu not associated with a menu bar to be displayed on the windows), explaining why I'm currently doubting whether it's feasible or not with a menu item.
I would greaty appreciate if you could provide some code sample along your response.
EDIT :
To clarify my first post, I'm trying to do something similar to this app :
It's the application that comes along the 3D connexion mouse whose usage is to parametrize each button.
As you can see, there are several sub-menu items. By clicking on the arrow next to a textbox, you open a sub-menu containing itself folders that contains themselves paramaters.
I have a QTabWidget with several tabs, every tab containing a QTableWidget with numbers. Outside of this QTabWidget, I have one button. When the button is pressed, the currently selected widget should be processed. The QTableWidgets are identical in their structure, they just display numbers, and if I have a pointer to one of these widgets, I cannot deduce which tab it came from.
A simple method to identify which widget is currently selected is to call currentIndex(). But this will break when I reorder the tabs in the designer and is probably not working with movable tabs.
Another way is to use currentIndex() and tabText(int index). Like this I have a stable way to find out which tab is currently selected. The disadvantage of this is that I am then dependent on having unique tab texts, and I in general don't like to rely on a UI property to implement functionality.
My solution for now is to give every Widget a different accessible name that I can then read out like this:
QWidget* widget = tabWidget->currentWidget();
QString* name = widget->accessibleName();
This works, but I wonder if there is a better solution, something like the Qt::UserRole that can be assigned to any cell in a QTableWidget.
Forgive me if this question is silly but I want to know
if there is a way to change the content of a menu bar in different
page on a stacked widget directly in qt designer.
For example I want the menu of the menu bar for page 1 of the stacked widget to be menu, inbox, multimedia, exit. For the second page I want the menu bar to contain the following menu; Text, outbox, contact, back. The reason is because
I want different menu controls for different pages of the
QstackeWidget. Is this possible from the qt designer ui or I'll have
to ultimately do it programatically?
As far as I know (which is QtCreator 3.3.0) the Creator only supports graphically inserting and editing a menu bar in QMainWindow. So for the first part of your question: Yes, you probably have to create the menus programmatically.
For the second part, it is possible to insert a menu bar in any given layout using QLayout::setMenuBar. This also includes the layout inside your stacked widget.
See also: Can you add a toolbar to QDialog?
Give me a tip please how to add different kinds of buttons (I need to have pushbuttons and radio buttons) on the same CToolBar.
You need to use CMFCToolbar::ReplaceButton.
You replace the regular button with either one of the default CMFCToolBarButton derived classed or with one of your own derived class.
The toolbar need to have a "placeholder" button (empty button) at the position you want to replace the button.
for example to replace a toolbar button with a combo box:
CMFCToolBarComboBoxButton myCombo(IDC_BUTTON_TO_REPLACE, GetCmdMgr()->GetCmdImage(IDC_BUTTON_TO_REPLACE, FALSE), CBS_DROPDOWNLIST, 80);
myCombo.m_strText.LoadString(IDS_MY_STRING);
myToolbar.ReplaceButton(IDC_BUTTON_TO_REPLACE, myCombo);
There are a couple of standard "buttons" available (in particular):
CMFCToolBarEditBoxButton to replace a toolbar button with an edit box.
CMFCToolBarDateTimeCtrlImpl to replace a toolbar button with a date picker
CMFCToolBarComboBoxButton to replace a toolbar button with a combo box.
(there are a couple more for menus and one for "outlook" ).
Good luck.
Can anyone explain how to add dropdown arrows to CMFCToolBar toolbar buttons - like for undo/redo buttons. We had this with CToolBar by using the TBSTYLE_EX_DRAWDDARROWS style and TBN_DROPDOWN notification. This doesn't seem to work with CMFCToolBar. These dropdown arrows i believe are added to the VisualStudioDemo MFC feature pack demo but i can not figure out how.
In the VisualStudioDemo sample, in CMainFrame::OnToolbarReset they replace the Undo button of the toolbar with a custom class called CUndoButton, like this:
m_wndToolBar.ReplaceButton(ID_EDIT_UNDO, CUndoButton(ID_EDIT_UNDO, _T("&Undo")));
CUndoButton is declared in file "UndoBar.h" of the sample project, so you can use it or change it however you like.