Pyqt5 de birden fazla buton kullanım

selamlar pyqt5 designer kullanarak bir ana pencere tasarladım bu pencerede 8 tane butonum bulunmakta bu butonlara tıklanınca bir tıklanma hissi yaratmak için kod kısmında butonun rengini değiştirmek istşyorum her butonun nesne ismine veya diğer ayırt edici özelliklerine erişmeme rağmen tıkladığım butonun rengini değiştiremedim yardımlarınız için şimdiden teşekkürler.

    from PyQt5.QtWidgets import *
    from Main_window  import Ui_MainWindow

        class kuzu(QMainWindow):
        	def __init__(self):
        		super().__init__()

        		self.ui = Ui_MainWindow()
        		self.ui.setupUi(self)

        		self.ui.buttongroup = QButtonGroup()

                    self.ui.buttongroup.buttonClicked[int].connect(self.button_pressed)
    		self.ui.buttongroup.addButton(self.ui.btn_yeni_hayvan,1)
    		self.ui.buttongroup.addButton(self.ui.btn_hayvan_listesi,2)
    		self.ui.buttongroup.addButton(self.ui.btn_grup,3)
    		self.ui.buttongroup.addButton(self.ui.btn_yeni_seans,4)
    		self.ui.buttongroup.addButton(self.ui.btn_seans_listesi,5)
    		self.ui.buttongroup.addButton(self.ui.btn_planlar,6)
    		self.ui.buttongroup.addButton(self.ui.btn_envanter,7)
    		self.ui.buttongroup.addButton(self.ui.btn_toplu_veri,8)


    	def button_pressed(self,btn_id):
    		print(object(self.ui.buttongroup.button(btn_id).objectName()))

yapmak istediğim

self.ui.btn_yeni_hayvan.setStyleSheet("""border-radius: 5px; 
		background-color: qlineargradient(spread:pad, x1:0.954, y1:0.0343636, x2:0.208, y2:1,
		stop:0.258883 rgba(0, 0, 0, 255), stop:0.939086 rgba(0, 255, 255, 255));color: rgb(121, 255, 164);""")

yokmu yardım edecek kimse

Merhaba şuan bilgisayarım yanımda değil, kod atamıyorum. Şu gönderiyi incelediniz mi?

1 Beğeni

çok teşekkür ederim inceleyince sorunu çözdüm kodu buraya bırakayım faydalanırlar

                self.ui.buttongroup = QButtonGroup()

                self.ui.buttongroup.buttonPressed[int].connect(self.button_pressed)
		self.ui.buttongroup.buttonReleased[int].connect(self.button_released)
		self.ui.buttongroup.addButton(self.ui.btn_yeni_hayvan,1)
		self.ui.buttongroup.addButton(self.ui.btn_hayvan_listesi,2)
		self.ui.buttongroup.addButton(self.ui.btn_grup,3)
		self.ui.buttongroup.addButton(self.ui.btn_yeni_seans,4)
		self.ui.buttongroup.addButton(self.ui.btn_seans_listesi,5)
		self.ui.buttongroup.addButton(self.ui.btn_planlar,6)
		self.ui.buttongroup.addButton(self.ui.btn_envanter,7)
		self.ui.buttongroup.addButton(self.ui.btn_toplu_veri,8)


	def button_pressed(self,button_id):
		for button in self.ui.buttongroup.buttons():
			if button is self.ui.buttongroup.button(button_id):
				button.setStyleSheet("""border-radius: 5px; 
				background-color: qlineargradient(spread:pad, x1:0.954, y1:0.0343636, x2:0.208, y2:1,
				stop:0.258883 rgba(0, 0, 0, 255), stop:0.939086 rgba(0, 255, 255, 255));color: rgb(121, 255, 164);""")

	def button_released(self,button_id):
		for button in self.ui.buttongroup.buttons():
			if button is self.ui.buttongroup.button(button_id):
				button.setStyleSheet("""border-radius: 5px; 
			background-color: qlineargradient(spread:pad, x1:0.137056, y1:0.892, x2:1, y2:0, stop:0.213198 rgba(0, 0, 0, 255),
			stop:0.939086 rgba(0, 255, 255, 255));color: rgb(121, 255, 164);""")