QTreeWidget: Windows Explorer-like editing - c++

I want to create a QTreeWidget where the items are both editable and launchable. I want it to behave like Windows Explorer:
Single click -> selection
Single click on a previously selected item -> open LineEdit to edit the name
Double click -> perform the 'launch'
So I created slots for itemClicked() and itemDoubleClicked(). The first one is the following:
def EditName(self, item, column):
if self.lastclick == item:
self.editItem(item)
self.lastclick = item
The second one just 'launches' the file.
However, this kind of solution doesn't distinguish between a double click and two consecutive clicks, so the QLineEdit still appears after a double click. Is it possible to get rid of the editor forcibly? I tried a hack solution like hiding and showing the item but it didn't work.

You just need to set flags on your QTreeWidgetItem to include the ItemIsEditable option, and set the edit triggers on the QTreeWidget for SelectedClick
def populate( self, tree ):
tree.setEditTriggers(tree.SelectedClicked)
for i in range(10):
item = QTreeWidgetItem(['Testing %02i' % i])
item.setFlags(item.flags() | item.ItemIsEditable)

Related

Delete currently selected item from QTreeWidget

Im working with a Qt GUI application, and i have a QTreeWidget with values.
I have added each value to the tree like so:
QTreeWidgetItem *node = new QTreeWidgetItem();
node->setText(0, m_stringList[i];
node->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemisDragEnabled);
ui->sourceTreeWidget->addTopLevelItem(node);
What i am trying to implement now, is a delete button to allow the user to select one or multiple tree items by clicking them, and then pressing the delete button.
The button part is easy.
The part i need some help with, is finding out how to retrieve the string/text value of the currently selected tree item(s).
Anyone have some tips or hints?
What exactly is your problem with that? You create a SLOT for the button and retrieve a list of the selected items with
QList<QTreeWidgetItem*> sel_items = ui->sourceTreeWidget->selectedItems();
for(int i=0; i<sel_items.size(); i++){
...
}
as stated in the documentation for QTreeWidget. You may then iterate through the list and delete them directly or simply retrieve the string/text value as you asked.

how to add checkbox control to the listcontrol subitems in mfc

I need to add checkbox control to the listcontrol subitems .First I will let you know what I did,Initially i added a listcontrol of report style and added checkbox style to the listview as follows.
m_MfpListControl.SetExtendedStyle(LVS_EX_CHECKBOXES);
This step of code is adding checkboxes to the first most column.But,I want to add checkbox to the subitems randomly like as,
Column1 | Column2 | Column3 | COlumn4
[]Item1 | []subitem1 | []subitem2 | [] subitem3
[]-Represents Checkbox
Adding for the "Item1" is not a big deal but adding to the subitems making me down and moreover I tried in manny ways like as after inserting item ,I am setting the state for the particular item as,
m_MfpListControl.SetItemState(0,INDEXTOSTATEIMAGEMASK(3),LVIS_STATEIMAGEMASK);
But this also didn't work fine ,as I am able to add and remove the checkbox for the first column ,I tried in a way of applying the same methodology like setting the item state as I had done using "SetItemState()" API in order to add the checkbox control to the subitems ,unfortunately it is not working in case of subitems.
Can anyone please let me know the right approach so that I should be able to add checkboxes to the subitems.
I use this class to add check boxes on subitems:
http://www.codeproject.com/Articles/8112/CQuickList
It requires LVS_OWNERDATA. In my case, it's not a problem.
This class also adds check boxes on subitems, but without LVS_OWNERDATA:
http://www.codeproject.com/Articles/29064/CGridListCtrlEx-Grid-Control-Based-on-CListCtrl
Vinicius

Lotus Notes: Dialog list - refresh fields on keyword change not working

I have a dialog list which use Use View dialog for Choices.
I have a row in a table which its appearing depends on the value selected from that dialog list. ( I am using Hide when formula... ) The form has Automatically refresh fields checked.
The problem is that after I select a certain value from the dialog list, and I even had selected Refresh fields on keyword change property, I MUST hit F5 or just TAB ( to go to a next field ) in order to make that row table to appear. I also tried to add uidoc.Refresh at the Exiting/OnChange event(s) of the dialog list.
I have noticed the following:
the refresh works fine for combo box, list box, radio button or check box
the refresh works fine for dialog list where you are using a list of choices / formula.
the refresh doesn't work for dialog list where you are using view dialog for choices ( my case ).
Is there any solution for this issue? I want when I selected a value from the dialog list, immediately the row / line should appear/disappear.
Thank for your time!

Make list value selected - sencha touch

I have overlay in which I am having one list component.
I am selecting multiple list items from that.
I am pressing OK button and my overlay is getting disappeared.
Now What I want is :
When I open that overlay again , I want those previously selected items highlighted.
I want to do this in sencha touch.
When you open your overlay again, previously selected items should be shown or highlighted.
As per my understanding, When you click on Ok button, You would be passing selected values as extra parameter in store to load it again.
so, when you open that overlay again, you would have those extraparams in the store...so, you can do below things. I am sure, It will work.
var store = Ext.getStore('storeId'),
selectedItems[],
selectedRec,
selectedRecs = [],
extraparameter = store.getProxy().extraParameters;
You can get selected transaction types like this.
selectedItems = extraparameter.selectedItems
Ext.Array.each(selectedItems , function(selectedItem) {
selectedRec = multiSelect.getStore().findRecord('transaction_type', transactiontype);
selectedRecs.push(selectedRec);
});`
Thanks !

How do I put a checkmark on a menu item that has submenu items. (Visual studio 2008 C++/MFC)

I have a menu that contains submenus.
eg:
Item1
Item2
Item3
item A
Item B
Item3 has items under it.
At any given time 1, 2, or the items under 3 should be checked. Since I don't have an ID for Item3 I have to use the MF_BYPOSITION indicator when I try to set a check on Item3 to indicate one of its children has a checkmark. Item3 should have a checkmark if A or B are checked. I am able to check items 1 and 2 and A and B - but can't figure out item3.
I have not been able to successfully use either ::CheckMenuItem() or ModifyMenu() to set the check mark.
Can someone point me to an example that does this successfully? The docs seem to indicate it can be done, but I have been unable to do it.
EDIT
This is for a menu that is set as the menu for a dlg box. The menu bar has three items - one of which drops down to what is shown above.
Note also, it is used as a popup for a right click, but I will take any suggestions to work in either case.
I've done this before for popup menus. You will need to access the submenu by position, instead of ID. Using your example above, Item 3 would be at position 2:
CMenu popupMenu;
popupMenu.LoadMenu(IDR_MYMENU);
popupMenu.GetSubMenu(0)->CheckMenuItem(2,MF_BYPOSITION|MF_CHECKED);
.
.
.
popupMenu.GetSubMenu(0)->TrackPopupMenu(...);
However, I haven't done this with items in the menu bar.
EDIT by Tim the OP:
For completeness
To get it to work with the menu item you have to get the hmenu
// MENU_POSITION is the zero based location of the menu you want to use. (file, edit, view, help... etc)
HMENU mainMenu = ::GetMenu(m_hWnd);
HMENU subMenu = GetSubMenu( mainMenu, MENU_POSITION);
SetMenuState(subMenu);
A few moments ago I had a similar problem - a standard MFC menu bar containing at least one submenu, and the need to be able to add a check mark to the submenu parent item, when any of the submenu child items were checked.
The easiest solution (for me) turned out to be as simple as performing the update in the standard OnUpdateMenuItem(CCmdUI* pCmdUI) call. In my case I used ON_UPDATE_COMMAND_UI_RANGE() to feed a bunch of menu IDs into the same update call, but the principal is the same for a single ON_UPDATE_COMMAND_UI() map.
The code I used (edited to be more easily inserted into other people's work) is:
void CMyApp::OnUpdateMenu(CCmdUI* pCmdUI)
{
// Note, a submenu parent (which has no editable ID in the resource editor) has the SAME ID as the first child item
if (pCmdUI->m_nID == ID_FIRST_CHILD_MENU && pCmdUI->m_pSubMenu != NULL) {
// Get the child menu so we can see if any child items are checked
CMenu* pSubMenu = pCmdUI->m_pSubMenu;
BOOL fChildChecked = FALSE;
for (UINT i = 0; !fChildChecked && i < pSubMenu->GetMenuItemCount(); ++i) {
// Do something to decide if this child item should be checked...
UINT nChildID = pSubMenu->GetMenuItemID(i);
fChildChecked = IsThisChildChecked(nChildID);
}
// The POSITION of the current menu item is stored in pCmdUI->m_nIndex
CMenu* pMenu = pCmdUI->m_pMenu;
UINT flags = MF_BYPOSITION;
if (fActiveChild) flags |= MF_CHECKED;
pMenu->CheckMenuItem(pCmdUI->m_nIndex, flags);
}
// Set the enabled state of the menu item as you see fit...
pCmdUI->Enable(TRUE);
}
Et voilĂ  the submenu item automagically gains a check mark when any of its child menu items has a check mark.
Hope this helps others looking for similar solutions!
John