Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QStandardItemModel setIcon not working ?
Forum Updated to NodeBB v4.3 + New Features

QStandardItemModel setIcon not working ?

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 357 Views
  • 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.
  • J Offline
    J Offline
    Johnson9070
    wrote on last edited by
    #1

    Hi all,
    I have a Qtableview showing data from a pandas dataframe using the QStandardItemModel.
    I can set the color of a cel through:

    item=self.model.item(2,2)
    item.setBackground(QBrush(Qt.red))
    

    But this doesn't work: item.setIcon(QtGui.QIcon("calendar.png"))
    I tried different ways to call it but nothing works , i want to set an icon next to the text.

    Can anyone help ?

    Cheers , John

    JonBJ 1 Reply Last reply
    0
    • J Offline
      J Offline
      Johnson9070
      wrote on last edited by
      #3

      Thx JonB , the file was in the same directory , after using absloute path it worked ;-)

      1 Reply Last reply
      0
      • J Johnson9070

        Hi all,
        I have a Qtableview showing data from a pandas dataframe using the QStandardItemModel.
        I can set the color of a cel through:

        item=self.model.item(2,2)
        item.setBackground(QBrush(Qt.red))
        

        But this doesn't work: item.setIcon(QtGui.QIcon("calendar.png"))
        I tried different ways to call it but nothing works , i want to set an icon next to the text.

        Can anyone help ?

        Cheers , John

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @Johnson9070 said in QStandardItemModel setIcon not working ?:

        QtGui.QIcon("calendar.png")

        That is a relative path name, you do not know where your current working directory is. Use an appropriate absolute path.

        1 Reply Last reply
        1
        • J Offline
          J Offline
          Johnson9070
          wrote on last edited by
          #3

          Thx JonB , the file was in the same directory , after using absloute path it worked ;-)

          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