DDR
8th August 2018, 22:14
Hello everyone,
I've assigned a stylesheet to a button. How would I go about animating the margins? I figure the first step is to retrieve the current margin, since that's what I want to animate to. I can't figure it out though...
from PyQt5 import QtWidgets
QtWidgets.QApplication([])
b = QtWidgets.QPushButton()
b.setStyleSheet("margin: 15px")
b.contentsMargins().top() #is 0, should be 15
The final line produces 0 instead of the expected value of 15.
b.style().subElementRect(QtWidgets.QStyle.SE_PushB uttonFocusRect, QtWidgets.QStyleOptionButton())
b.style().subElementRect(QtWidgets.QStyle.SE_PushB uttonFocusRect, QtWidgets.QStyleOptionButton(), b)
Carrying on, both these lines then print "Segmentation fault" and exit Python. They didn't return anything particularly sensible in my actual app anyway.
Does anyone have any suggestions? I'm trying to make a little 'slide-in' effect for my menu, but I want the buttons to always be clickable even when they haven't slid in yet. I was planning to do it by adjusting the margin-left from my menu width to the original value of margin-left.
Thanks,
–DDR
I've assigned a stylesheet to a button. How would I go about animating the margins? I figure the first step is to retrieve the current margin, since that's what I want to animate to. I can't figure it out though...
from PyQt5 import QtWidgets
QtWidgets.QApplication([])
b = QtWidgets.QPushButton()
b.setStyleSheet("margin: 15px")
b.contentsMargins().top() #is 0, should be 15
The final line produces 0 instead of the expected value of 15.
b.style().subElementRect(QtWidgets.QStyle.SE_PushB uttonFocusRect, QtWidgets.QStyleOptionButton())
b.style().subElementRect(QtWidgets.QStyle.SE_PushB uttonFocusRect, QtWidgets.QStyleOptionButton(), b)
Carrying on, both these lines then print "Segmentation fault" and exit Python. They didn't return anything particularly sensible in my actual app anyway.
Does anyone have any suggestions? I'm trying to make a little 'slide-in' effect for my menu, but I want the buttons to always be clickable even when they haven't slid in yet. I was planning to do it by adjusting the margin-left from my menu width to the original value of margin-left.
Thanks,
–DDR