Tab order in QDialog always moving to QTableWidget last - c++

I have a QDialog that contains a bunch of fields, buttons and a custom widget that inherits QTableWidget somewhere in the middle. I have the tab order set up the way I want it and it works fine, but only the first time though. After focusing on the last widget in the tab order and pressing tab again the focus goes back to the custom QTableWidget! It doesn't go back to number 1 in the tab order!
I have tried changing the tab order to something else and I still get the same result. After tabbing out of the last widget the focus goes to the table (which is #26 out of 38 in the tab order) instead of the first field.
I have tried setting "NoFocus" on the main QDialog and the custom table widget itself. I am also not using setTabOrder() anywhere on the QDialog or on my table widget.
What could be going on?

Related

Implement modular drag & drop system for QListWidget

I tried to implement a modular drag and drop system for this window, which has a lot of QListWidgets in other tabs.
Currenty, the user is only able to copy the items from the right QListWidget (at the button "Tools"). But now I want to implement a simple option to copy all selected QListWidgetItems from any QListWidget.
My plan
Drag the selected items out of the QListWidget
A section with a button named "copy" appears
The user drop the dragged QListWidgetItems on the copy button
The copy button disappears
The result is a QList<QListWidgetItem*> with the dropped QListWidgetItems
The problems
(-)
I'd need a signal when the drag starts / is called
(-)
I'd need a signal when the drop starts / is called
How to get QList<QListWidgetItem*> (or QListWidget::selectedItems)?
I want a modular opportunity (for example with a pointer to the QListWidget) because I don't want to copy some code. For example, I have 12 QListWidgets and for each 3 actions. If I want to change a litte thing, I need to do that 36 times.
Is it possible without subclassing?

SetFocus and KillFocus

I have a CMFCTabCtrl in my dialog and my CMFCTabCTrl has two tabs.
The first tab has a CComboBox and the second tab also has a CComboBox.
Whatever item newly added in ComboBox in first tab will reflect in ComboBox in second tab. Similarly, whatever item newly added in ComboBox in second tab will reflect in ComboBox in first tab.
For this, I have all ComboBox items in a vector and in each dialog's WM_SETFOCUS event I am adding items to ComboBox.
When user typing something in ComboBox but then user selects another control or dialog/tab also I am adding that item to ComboBox. For that I am tracking CBN_KILLFOCUS in parent's dialog OnCommand and adding the item to ComboBox.
Now my problem is when user type something in ComboBox and clicking on second tab, the SetFocus of second tab is called first and then only OnCommand with CBN_KILLFOCUS() message is getting called. So the second tab is not having newly added item by the first tab whereas the first tab is having that item.
How to make the ComboBox item available to the second tab before it is getting displayed.
If I do necessary operation(whatever operation I am doing on killfocus) on AFX_WM_CHANGING_ACTIVE_TAB, I am able to achieve my requirement.

PYQT4 List item contents are disappearing when inserting it back into the list

I have a pyqt4 setup with a custom widget as the item of the listwidget. I have two buttons in that custom widget to move it up or down the list by taking it and inserting it either 1 up or 1 down.
When it is inserted the item is still highlighted but the contents are gone.
Here is what is moving the item.
def ChangeInit(self, row, direction):
item = self.initiativeList.takeItem(row)
self.initiativeList.insertItem(row + direction, item)
row = the row the item is in
direction = 1 or -1 depending on which button is pressed
Any ideas why the item appears to be moved but the contents of it not being moved with it or at least not visible?
Let me know if you need more info.
The documentation of QListWidget.addItem states:
Warning: A QListWidgetItem can only be added to a QListWidget once. Adding the same QListWidgetItem multiple times to a QListWidget will result in undefined behavior.
Although this can be interpreted in more than one way (i.e. adding one widget multiple times simultaneously, or adding it sequentially like you do) I sugest that you create a completely new QListWidgetItem object and insert that in the list, just to be sure. Otherwise I don't know if Qt will handle the underlying indices correctly.
P.S. next time I would add the general PyQt label unless it is a problem specific to PyQt4. This might get you some more views (you now only have two after 23 hours).

Start drag action from a menu item

Given a QTreeView I would like to provide the user a means of inserting new items. For this I created a QMenuBar that contains several categorizing sub menus that in turn contain the different kinds of items the user can insert.
My first implementation was to select some existing item in the tree and then pick a menu item which is then inserted as a child of the selected item in the tree. There were buttons for rearranging the items, such as 'move up', 'move down' and so on. Later I replaced these buttons by a drag&drop interface where the user can simply drag items in the QTreeView around to rearrange them, which seems quite intuitive to me.
Now inserting new items into the tree by clicking menu items still feels annoying. In my opinion a more natural approach would be to drag the items out of the menu and into the desired location of the tree.
So is there a sensible way to implement this behaviour? My problem is how to start a drag operation by clicking a menu item as the triggered() signal is just emitted when the user releases the mouse button. But with the mouse button released, there is no drag anymore...

making a QToolButton checked with a QMenu

I am designing a widget which has a grid of buttons. When clicked I want these buttons to present the user with 3 choices (ideally in a small drop down menu) that they can select from. When they select 1 of the 3 choices, I want that button to be selected (i.e., remain depressed). I want the QAction that is associated with each of the 3 choices to be able to know which button was clicked so that I can log which button in the grid was clicked. Each button in the grid needs to be exclusive, and when selected. The 3 choices presented are the same for all buttons.
I first started with a QButtonGroup and QPushButtons in a QGridLayout. I was able to get the buttons to be exclusive as I wanted. When I changed the buttons from QPushButton to QToolButton, and added a drop down menu, two things happened:
When they select an item from the menu, the button doesn't stay depressed like I want it to.
I can't seem to see a way for the menu action to be informed about which button was selected, so I am unable to log which button is selected.
Any thoughts on how I can achieve the functionality I am looking for?
EDIT:
A few clarifying points:
Each button in the m x n grid represents a person.
The drop down list on each button lets you select what action that person is currently doing.
Only one person can be doing something at a time. Hence, only one button in the entire grid can be depressed at a time.
The items in the button drop down menu should become checked when they are selected, and these items need to be exclusive, so if a button is clicked twice, the a new checked menu item in the drop down menu should uncheck the previous one.
When an item in the button drop down menu is selected, the menu should go away and the button should appear depressed.
I need to log the button (i.e., the row and column) that was clicked as well as the choice selected from the button drop down menu. So somehow menu item signal/slot needs to know about which button was clicked. However, QToolButton::setMenu() doesn't transfer ownership of the Menu to the QToolButton, so I'm not sure how to make the signals/slots in the QActions of the QMenu aware of which button was selected.
QObject::sender will tell you what QObject emitted the signal