This question already has an answer here:
- How to create a circular button in Qt Designer 1 answer
I try to create a circle button but in fact pyqt still creates a square button.All examples found just creates square buttons and put a round image in it but still when i try to hide background of the button it fails.I also try to add some hover function but this should work afterwords so you can skip it.My code is here:
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QAction
from PyQt5.QtGui import QPalette
# from video import VideoWindow
import sys
class HoverButton(QtWidgets.QToolButton):
def __init__(self, parent=None):
super(HoverButton, self).__init__(parent)
self.setMouseTracking(True)
def enterEvent(self,event):
# print("Enter")
self.setStyleSheet('''
border-image: url("images/exit.jpg") 10 10 2 2;
border-top: 10px transparent;
border-bottom: 10px transparent;
border-right: 2px transparent;
border-left: 2px transparent''')
self.setGeometry(QtCore.QRect(1100, 550, 160, 161))
def leaveEvent(self,event):
self.setStyleSheet('''
border-image: url("images/exit.jpg") 10 10 2 2;
border-top: 10px transparent;
border-bottom: 10px transparent;
border-right: 2px transparent;
border-left: 2px transparent''')
self.setGeometry(QtCore.QRect(1100, 550, 140, 141))
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1371, 924)
MainWindow.setAcceptDrops(True)
self.button = HoverButton(self)
self.button.setGeometry(QtCore.QRect(1100, 550, 140, 141))
self.button.setStyleSheet('''background: transparent;
border-image: url("images/exit.jpg") 3 10 3 10;
border-top: 3px transparent;
border-bottom: 3px transparent;
border-right: 10px transparent;
border-left: 10px transparent;
''')
self.button.setObjectName('button')
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Output: