What I want to do is pop a list when the user right clicks on the slider offering some optional things to do. All the sliders will do the same thing, but just act on the slider that was right clicked.
I got, what I assume is a kludge way of doing it, working:
In the init for the dialog:
self.slider_entered = ''
self.sldr_actions_list = []
self.sldr_action_names = ['Set Min', 'Set 0db', 'Propagate level']
for action_name in self.sldr_action_names:
newaction
= QAction(action_name, None
) newaction.triggered.connect(eval('self.slider_action_{}'.format(action_name.replace(' ', '_').lower())))
self.sldr_actions_list.append(newaction)
self.slider_entered = ''
self.sldr_actions_list = []
self.sldr_action_names = ['Set Min', 'Set 0db', 'Propagate level']
for action_name in self.sldr_action_names:
newaction = QAction(action_name, None)
newaction.triggered.connect(eval('self.slider_action_{}'.format(action_name.replace(' ', '_').lower())))
self.sldr_actions_list.append(newaction)
To copy to clipboard, switch view to plain text mode
When the slider is added:
sldr = MySlider()
sldr.setContextMenuPolicy(Qt.ActionsContextMenu)
sldr.addActions(self.sldr_actions_list)
sldr = MySlider()
sldr.setContextMenuPolicy(Qt.ActionsContextMenu)
sldr.addActions(self.sldr_actions_list)
To copy to clipboard, switch view to plain text mode
MySlider inherits from QSLider and has:
def enterEvent(self, m_ev):
self.window().slider_entered = self.objectName()
def enterEvent(self, m_ev):
self.window().slider_entered = self.objectName()
To copy to clipboard, switch view to plain text mode
and the code for the actions in the dialog, set min in this case:
def slider_action_set_min(self):
act_sndr = self.sender()
sldr
= self.
window().
findChild(QtWidgets.
QSlider, name
=self.
slider_entered) print('Set slider to min. Current value: {}'.format(sldr.value()))
self.slider_set(self.slider_entered, 0)
def slider_action_set_min(self):
act_sndr = self.sender()
sldr = self.window().findChild(QtWidgets.QSlider, name=self.slider_entered)
print('Set slider to min. Current value: {}'.format(sldr.value()))
self.slider_set(self.slider_entered, 0)
To copy to clipboard, switch view to plain text mode
What I want to do is pop a list when the user right clicks on the slider offering some optional things to do. All the sliders will do the same thing, but just act on the slider that was right clicked.
I got, what I assume is a kludge way of doing it, working:
In the init for the dialog:
self.slider_entered = ''
self.sldr_actions_list = []
self.sldr_action_names = ['Set Min', 'Set 0db', 'Propagate level']
for action_name in self.sldr_action_names:
newaction
= QAction(action_name, None
) newaction.triggered.connect(eval('self.slider_action_{}'.format(action_name.replace(' ', '_').lower())))
self.sldr_actions_list.append(newaction)
self.slider_entered = ''
self.sldr_actions_list = []
self.sldr_action_names = ['Set Min', 'Set 0db', 'Propagate level']
for action_name in self.sldr_action_names:
newaction = QAction(action_name, None)
newaction.triggered.connect(eval('self.slider_action_{}'.format(action_name.replace(' ', '_').lower())))
self.sldr_actions_list.append(newaction)
To copy to clipboard, switch view to plain text mode
When the slider is added:
sldr = MySlider()
sldr.setContextMenuPolicy(Qt.ActionsContextMenu)
sldr.addActions(self.sldr_actions_list)
sldr = MySlider()
sldr.setContextMenuPolicy(Qt.ActionsContextMenu)
sldr.addActions(self.sldr_actions_list)
To copy to clipboard, switch view to plain text mode
MySlider inherits from QSLider and has:
def enterEvent(self, m_ev):
self.window().slider_entered = self.objectName()
def enterEvent(self, m_ev):
self.window().slider_entered = self.objectName()
To copy to clipboard, switch view to plain text mode
and the code for the actions in the dialog, set min in this case:
def slider_action_set_min(self):
act_sndr = self.sender()
sldr
= self.
window().
findChild(QtWidgets.
QSlider, name
=self.
slider_entered) print('Set slider to min. Current value: {}'.format(sldr.value()))
self.slider_set(self.slider_entered, 0)
def slider_action_set_min(self):
act_sndr = self.sender()
sldr = self.window().findChild(QtWidgets.QSlider, name=self.slider_entered)
print('Set slider to min. Current value: {}'.format(sldr.value()))
self.slider_set(self.slider_entered, 0)
To copy to clipboard, switch view to plain text mode
Added after 1 30 minutes:
I think I found the right way (or at least a better way)
When I create the slider:
sldr.setContextMenuPolicy(Qt.CustomContextMenu)
sldr.customContextMenuRequested.connect(self.sldr_action_click)
sldr.setContextMenuPolicy(Qt.CustomContextMenu)
sldr.customContextMenuRequested.connect(self.sldr_action_click)
To copy to clipboard, switch view to plain text mode
then the self.sender() in self.sldr_action_click is the slider.
Bookmarks