Python Forum
[PyQt] QSlider jump to mouse click position
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] QSlider jump to mouse click position
#3
Fixed it this way if anyone's interested:
class QJumpSlider(QtGui.QSlider):
	def __init__(self, parent = None):
		super(QJumpSlider, self).__init__(parent)
	
	def mousePressEvent(self, event):
		#Jump to click position
		window.seekMusic(QtGui.QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width()))
		self.setValue(QtGui.QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width()))
	
	def mouseMoveEvent(self, event):
		#Jump to pointer position while moving
		window.seekMusic(QtGui.QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width()))
		self.setValue(QtGui.QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width()))
where 'window' is the main app made in main() and seekMusic is a function from the MusicPlayer class:
if __name__ == "__main__":
	app = QApplication(sys.argv)
	app.setWindowIcon(QIcon("icons/logo.png"))
	window = MusicPlayer()
	window.show()
	sys.exit(app.exec_())
Reply


Messages In This Thread
QSlider jump to mouse click position - by MegasXLR - May-25-2018, 11:53 AM
RE: QSlider jump to mouse click position - by MegasXLR - May-26-2018, 08:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter - touchscreen, push the button like click the mouse John64 5 827 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  [Tkinter] Mouse click without use bind ATARI_LIVE 8 7,403 Oct-23-2020, 10:41 PM
Last Post: ATARI_LIVE
  [Tkinter] program unresponsive during pynput mouse click RobotTech 1 3,477 May-07-2020, 04:43 PM
Last Post: RobotTech
  [Tkinter] Mouse click event not working on multiple tkinter window evrydaywannabe 2 3,749 Dec-16-2019, 04:47 AM
Last Post: woooee
  QGraphicsObject at Mouse Position _meshman_ 2 4,380 Oct-27-2019, 02:36 PM
Last Post: _meshman_
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 4,996 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  [PyQt] `QPushButton` without mouse click animation Atalanttore 2 5,863 Apr-22-2019, 01:00 PM
Last Post: Atalanttore
  QTabBar Indexing is wrong for right mouse click xenas 2 2,516 Jan-04-2019, 10:08 PM
Last Post: xenas
  right mouse button click with PyQt5 brecht83 4 19,382 Nov-09-2018, 02:55 PM
Last Post: brecht83

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020