I'm trying to make a button like this
Currently I can create the middle two buttons (single right or single left) using Qt::LeftArrow
or Qt::RightArrow
from setArrowType()
. From the docs, there seems to only be 5 possible types. If this feature is not built in, how can I make a custom double arrow button?
Right now I have this
from PyQt4 import QtCore, QtGui
import sys
class PanningButton(QtGui.QToolButton):
"""Custom button with click, short/long press, and auto-repeat functionality"""
def __init__(self):
QtGui.QToolButton.__init__(self)
self.setArrowType(QtCore.Qt.LeftArrow)
# Enable auto repeat on button hold
self.setAutoRepeat(True)
# Initial delay in ms before auto-repetition kicks in
self.setAutoRepeatDelay(700)
# Length of auto-repetition
self.setAutoRepeatInterval(500)
self.clicked.connect(self.buttonClicked)
self._state = 0
def buttonClicked(self):
# Panning
if self.isDown():
if self._state == 0:
self._state = 1
self.setAutoRepeatInterval(50)
# Mouse release
elif self._state == 1:
self._state = 0
self.setAutoRepeatInterval(125)
def pressed():
global counter
counter += 1
print(counter)
if __name__ == '__main__':
app = QtGui.QApplication([])
counter = 0
panning_button = PanningButton()
panning_button.clicked.connect(pressed)
panning_button.show()
sys.exit(app.exec_())