@@ -169,17 +169,31 @@ def bin_context_menu_opened(self, position):
169
169
:param position: The position to open the menu, e.g. where
170
170
the mouse button was clicked
171
171
"""
172
- context_menu = self .setup_bin_context_menu (self .currentWidget ())
173
- context_menu .exec_ (self .currentWidget ().horizontalHeader ().mapToGlobal (position ))
172
+ table = self .currentWidget ()
173
+ context_menu = self .setup_bin_context_menu (table )
174
+ header = table .horizontalHeader ()
175
+ # If you right-click on a column header, then select that column, unless you're already clicking
176
+ # inside a selected column
177
+ index_of_selected_column = header .logicalIndexAt (position )
178
+ if index_of_selected_column not in [x .column () for x in table .selectionModel ().selectedColumns ()]:
179
+ table .selectColumn (index_of_selected_column )
180
+ context_menu .exec_ (header .mapToGlobal (position ))
174
181
175
182
def spectra_context_menu_opened (self , position ):
176
183
"""
177
184
Open the context menu in the correct location
178
185
:param position: The position to open the menu, e.g. where
179
186
the mouse button was clicked
180
187
"""
181
- context_menu = self .setup_spectra_context_menu (self .currentWidget ())
182
- context_menu .exec_ (self .currentWidget ().verticalHeader ().mapToGlobal (position ))
188
+ table = self .currentWidget ()
189
+ context_menu = self .setup_spectra_context_menu (table )
190
+ header = table .verticalHeader ()
191
+ # If you right-click on a row header, then select that row, unless you're already clicking
192
+ # inside a selected row
193
+ index_of_selected_row = header .logicalIndexAt (position )
194
+ if index_of_selected_row not in [x .row () for x in table .selectionModel ().selectedRows ()]:
195
+ table .selectRow (index_of_selected_row )
196
+ context_menu .exec_ (header .mapToGlobal (position ))
183
197
184
198
def setup_plot_bin_actions (self , context_menu , table ):
185
199
plot_bin_action = QAction (self .GRAPH_ICON , "Plot bin (values only)" , self )
0 commit comments