Is there a way to have multiple columns in a QMenu? - c++

Is there a way to have multiple columns in a QMenu? I'm using Qt with C++. I have searched and there does not seem to be a way to do this built in to Qt. The question then is how do I add this functionality to my program? Has anyone built a custom menu that can have multiple columns?

Maybe a submenu is what you're looking for. As qt doc says:
Separators are inserted with addSeparator(), submenus with addMenu(), and all other items are considered action items.
For example, here there is a full example. And "Format" menu item is a submenu. You can add a submenu with:
m_mysubmenu = QMenu(...);
...
m_menu->addMenu(m_mysubmenu);

I found a way to do this here. This is not normally something that you want to do; there is usually a better way; but in my application, the user will be greatly helped by it.

Related

Menu designed for use without mouse. What is the best way to implement?

I'm writing a GUI using QT for embedded system with linux. This device has no mouse. Only display and specific keyboard with keys: up, down, return and 7 number keys.
The software will be used to set some parameters of device and read them (some charts also).
Example of how menu could look:
after OPTION 1 selected
After SUBOPTION 1 selected some table with data is loaded.
Sometimes after selecting option i need to load specific widget and sometimes just another set of options.
I think it is possible to implement custom labels and kind of list widget that aligns them.
I guess it is also possible to use Qt's MVC classes for it. They are highly customizable, but i never made custom views and delegates.
Maybe i just need to create QtListView with stringlist model and apply stylesheet to it so it gets look more like buttons. And based on selection in list load next widget.
Which way is better and why?
Is there any easier ways to accomplish this?
Any ideas would be appreciated.

How can I sort Items in `CListCtrl` when the button is clicked?

How can I sort Items in CListCtrl when the button is clicked?
I made a Dialog based application in MFC.
I put CListCtrl control on my Dialog and set its view style to report type.
I have two columns in this list view.
In here when I clicked the "Sorting" button, it should sort item in the list.
I saw many examples related to this, but none is working for me.
Can some one guide me how to do that?
I assume that you mean the column header when you write "sorting button".
You probably forgot to put this into the message map of your dialog:
ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST1, OnColumnclickList1)
IDC_LIST1 is the id of the list control which may be different in your code.
Are you somewhat familiar with MFC ? If not, you should follow one of the numerous tutorials available on the net.
I would use a CMFCListCtrl. It is easier, as it as built in sorting functionality and you only have to provide a function with the comparing items algorithm for sorting. I have succeeded using it. You have to override the OnCompareItems on your class derived from CMFCListCtrl. I also recommend you to do a call to EnableMarkSortedColumn(); after your list is created.
The CListCtrl has a SortItems method.
All you need to do is provide your Compare function to it as the parameter.
I don't know much about the contents of your list control so I can't really give you more information.
Please read up on it and extend your question with example code and details of which column needs to be sorted and I can help more.
If the contents of your cells are just text then I usually just return the value of:
return Value1.CollateNoCase(Value2);
There are also lots of tutorials on the Internet. For example:
http://www.codeproject.com/Articles/27774/CListCtrl-and-sorting-rows
In fact, that tutorial suggests us in SortItemsEx. That is what I would use.

How can I add Windows right click context menu items?

I am trying to add new actions to the right click context menu when you select a file or many files. I am writing a program in C++ which contains the functionality that I want to trigger.
As far as I know I have to add new entries to the registers when installing my program and also, I have to use COM(here I got completely lost).
Is there a straightforward way of doing this?
As already suggested by #Igor Tandetnik you can do almost everything you want with Registry entries.
https://msdn.microsoft.com/en-us/library/windows/desktop/cc144169.aspx

Possible for ListCtrl Colspan, or similar functionality?

Is there a way to have a ListCtrl cell span several columns? Or perhaps to able to append a panel / other element to a ListCtrl item that will contain the info I need?
No. The ListCtrl does not support that functionality. There is a pure Python list control widget called the UltimateListCtrl that allows you add any widget to a cell, although it doesn't appear to allow cell spanning either. I would still try this widget and see if it works for you. If it does not, you may be able to patch it yourself because it's written in Python or you could do a feature request for it to be added to the UltimateListCtrl on the wxPython mailing list and see if anyone takes you up on it.
You can do spanning in a wx.Grid widget if you wanted to go that route, although it's pretty limited when it comes to embedding other widgets.

How to sort Item in CListCtrl in MFC?

I made a Dialog based application in MFC. I put CListCtrl control on my Dialog and set its view style to report type. I have five columns in this list view. All columns are of String type. I want to implement the sorting in this list, That is when I click on a column it should sort item in the list. I saw many examples related to this. but none is working for me. Can some one guide me how to do that???
Thanks
Since it is MFC, this sample and this sample should work.
List Sorting
This works perfectly. Thanks for your cooperation.