Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QIcon changes with the state of a QAction
Forum Updated to NodeBB v4.3 + New Features

QIcon changes with the state of a QAction

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hizoka
    wrote on last edited by
    #1

    Hi,
    I see it's possible to add multiple QPixmap in a QIcon: https://doc.qt.io/qt-5.10/qtwidgets-widgets-icons-example.html

    I 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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The icon is used in tool bar for the button generated from the action. However QAction has no visual representation in a QLineEdit.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hizoka
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved