Hello fellow developers!
I want to realize a "Action" QCombobox where the different options trigger an action instead of choosing an option. The combobox says something like "Add Property" and when the user clicks it, he gets the different properties to choose from. If the user clicks one of them, it is added to -whateverdoesntmatter-. The combobox than switches back to it's original state.
The problem is, that the first entry "Add Property" is shown on the combobox's drop down, causing a little bit of confusion for the user since it is not really an action.
Normal state:
[Add Property]
Drop-down state:
[Add Property]
Add Property
Length
Width
etc ...
Therefore, I want to hide the first option as soon as the combobox drops down to achieve this behavior:
[Add Property]
Length
Width
etc ...
I have already tried with subclassing the combobox and overwriting showPopUp() and hidePopUp() - but I could not figure out how to get my intended behavior.
Ideas? Thanks!
If you don't absolutely need a QComboBox you might be better/easier off using a QToolButton with a QMenu associated and then set the button's popupMode to an appropriate value.
You may even use a QToolBar. Simply add a QAction with your desired label (like Add Property), associate the menu to it via QAction::setMenu and at it to the toolbar. The toolbar will automatically create the tool buttons itself.
To access the popupMode property you can use QToolBar::widgetForAction and cast it to a QToolButton.
Related
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.
I have filled my NSPopUpButton with menu and submenus.
When I select a menuItem on the root menu (so, not a sub-menuItem), it propery displays the menuItem selected. And when I re-click on the popUp button, I get the selected menuItem under the mouse.
But if I select a sub-menuItem, it doesn't display it. And if I re-click on the popUp button, I don't get it under the mouse. Any time I click on the button, I have to look for the selected item diving in the menu hierarchy.
Any solution?
The Human Interface Guidelines state:
Avoid adding a submenu to an item in a pop-up menu. A submenu tends to
hide choices too deeply and can be physically difficult for users to
use.
I assume that since the practice is discouraged (albeit not that strongly) that it is not supported either. I can see how submenus would break some of NSPopUpButton's functionality, all of the item index related methods would not make sense. Those methods would have to use NSIndexPaths instead of simple indexes.
A potential substitute would be to use different indention levels in the menu to indicate hierarchy. I am about to try that myself.
i've a little comboBox, and i want to fill it with 6 entries... .
i wrote this code:
CComboBox* dropdownList = ((CComboBox*)GetDlgItem(IDC_PROGRAMDROPDOWN));
dropdownList->Clear();
dropdownList->AddString(L"test");
dropdownList->AddString(L"test2");
dropdownList->InsertString(2,L"test3");
dropdownList->InsertString(3,L"test4");
dropdownList->InsertString(4,L"test5");
As you can see I tried AddString(), and InsertString(). both with no effect. I also tried it just with AddString() which should be the correct way at initializing it.
But, my combobox is empty. I already debugged it, and this lines are hit but with no effect.
Do you have any idea?
In the dialog editor, make sure you resize the ComboBox item so that its height is big enough to contain all of the items when the ComboBox is expanded. By default, it'll only be the height of the "edit control" bit of the ComboBox, which limits the expanded height.
So, in the dialog editor, click on the dropdown button bit of the Combo Box and you should see the drag handles change a bit. Drag out the new size to account for all the items in the dropdown list.
thanks for all your answers. But it was an ugly Failure by my IDE -.-. I just recreated the UI-Element and it worked...
I recreated it with the same properties (Copy & Paste)
I have a map application and a submenu which has dynamically added objects (i.e. points on a map) added to the submenu, depending on the layer that is loaded. I have the ability to hide each individual objects (i.e. a point) by clicking on the corresponding submenu item. Is there any way to organize the submenu? When there are a lot of points (i.e. 100) the entire submenu takes up the screen. Can I add a scrollbar to a submenu? I looked in the documentation, but couldn't find anything that support this feature.
From this bug report I was able to find out that you could do the following:
submenu->setStyleSheet("QMenu { menu-scrollable: 1; }");
Works like a charm.
There is no such possibility as far as I know.
Maybe you shouldn't use a sub menu for this but prefer a menu entry that show a Point manager GUI of your own which would have a QListWidget displaying all your points items.
I'm aware that this solution will break a (big?) part of your code but I don't see anything else.
I think you may be able to get the effect you want by creating and using your own QStyle subclass (via QApplication::setStyle()), and overriding the styleHint virtual method to return 1 when the StyleHint parameter passed in is SH_Menu_Scrollable. At least, that works for me when I create large QMenu objects and show them as popup menus.... It may also work for QMenus attached to the menu bar, but I havent tried that.
Whilst it is possible by subclassing the QMenu class to create a custom widget and going from there you're better off looking at a better way to display that information. You'll save yourself time and it'll be much easier for your users to not have to scroll through a big list of items in a small area.
I have a CListCtrl with checkboxes. I want to be able to disable one of the items so that the user cannot click the checkbox. Is this possible? If so, how?
Edit:
Found the specifics on how to hide a checkbox in another question
Need only some rows in a CListCtrl control to have check boxes
Shortly: Not easily possible.
You'll need to sub-class the CListCtrl and implement this behavior on your own or download for example the MFC Grid Control that allows you to do that.
As for the removing check-boxes idea, yes, that might be possible, MSDN:
Version 4.70. Enables check boxes for items in a list-view control. When
set to this style, the control creates
and sets a state image list with two
images using DrawFrameControl. State
image 1 is the unchecked box, and
state image 2 is the checked box.
Setting the state image to zero
removes the check box.