QIcon changes with the state of a QAction
-
Hi,
I see it's possible to add multiple QPixmap in a QIcon: https://doc.qt.io/qt-5.10/qtwidgets-widgets-icons-example.htmlI would like to use it for a QAction in a QLineEdit, but that does not work ...
#! / usr / bin / python3 -u # - * - coding: utf-8 - * - import sys from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import * class caca (QDialog): def __init __ (self, parent = None): super (poo, self) .__ init __ (parent) self.Icons = QIcon () Pix1 = QIcon.fromTheme ("format-text-lowercase") pixmap (QSize (16,16)) Pix2 = QIcon.fromTheme ("dialog-cancel"). Pixmap (QSize (16,16)) Pix3 = QIcon.fromTheme ("dialog-ok"). Pixmap (QSize (16,16)) Pix4 = QIcon.fromTheme ("journal-new"). Pixmap (QSize (16,16)) Pix5 = QIcon.fromTheme ("view-refresh"). Pixmap (QSize (16,16)) Pix6 = QIcon.fromTheme ("edit-delete"). Pixmap (QSize (16,16)) Pix7 = QIcon.fromTheme ("edit-rename"). Pixmap (QSize (16,16)) Pix8 = QIcon.fromTheme ("journal-new"). Pixmap (QSize (16,16)) #self.Icons.addPixmap (Pix1, QIcon.Selected, QIcon.On) #self.Icons.addPixmap (Pix2, QIcon.Disabled, QIcon.On) self.Icons.addPixmap (Pix3, QIcon.Active, QIcon.On) #self.Icons.addPixmap (Pix4, QIcon.Normal, QIcon.On) # self.Icons.addPixmap (Pix5, QIcon.Selected, QIcon.Off) #self.Icons.addPixmap (Pix6, QIcon.Disabled, QIcon.Off) self.Icons.addPixmap (Pix7, QIcon.Active, QIcon.Off) #self.Icons.addPixmap (Pix8, QIcon.Normal, QIcon.Off) self.IconAction = QAction () self.IconAction.setCheckable (True) self.IconAction.setIcon (self.Icons) self.lineEdit = QLineEdit (self) self.lineEdit.addAction (self.IconAction, QLineEdit.LeadingPosition) self.pushButton = QPushButton (self) self.pushButton.setCheckable (True) self.pushButton.setIcon (self.Icons) self.verticalLayout = QVBoxLayout (self) self.verticalLayout.addWidget (self.pushButton) self.verticalLayout.addWidget (self.lineEdit) self.show () app = QApplication (sys.argv) cacaClass = poo () cacaClass.setAttribute (Qt.WA_DeleteOnClose) app.exec ()
It's ok with the button but not with the QAction ...
Any Idea?Yes, I can change the QIcon when the Qaction is toggled with a event ... but I would like to do only with the QIcon: p
-
Hi,
The icon is used in tool bar for the button generated from the action. However QAction has no visual representation in a QLineEdit.
-
@SGaist said in QIcon changes with the state of a QAction:
Hi,
The icon is used in tool bar for the button generated from the action. However QAction has no visual representation in a QLineEdit.Ok, so it' impossible like this, thank you :)
I will continue to use the toggled event.