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. QTableWidgetItem stylesheet control limitation
Qt 6.11 is out! See what's new in the release blog

QTableWidgetItem stylesheet control limitation

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 3 Posters 2.0k 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.
  • alomA Offline
    alomA Offline
    alom
    wrote on last edited by alom
    #1

    I'm trying to add a white triangle in the selected row of a QTableWidget to the last table item.
    currently i'm achieving this by setting a style sheet:

    QTableView::item:selected
    {
        color: rgb(222, 105, 89);
        background: rgb(43, 43, 43);
        outline: none;
        background-image:url('ui/table_item_selected.png');
        background-repeat: no-repeat;
        background-position: center right;
    }
    

    Unfortunately, this also adds the png file to the other items in the selected row.

    I've tried to add a dynamic property to the last item using setProperty(), to use another stylesheet setting, but i get a:

    AttributeError: 'PySide2.QtWidgets.QTableWidgetItem' object has no attribute 'setProperty'
    

    I've also tried to use

    image = QtGui.QPixmap('ui/main_nav_selected.png')
    tb_item.setBackground(QtGui.QBrush(image))
    

    but that repeats the image on the last cell and seems to conflicts with my style sheet for the selected row (as i'm using background: rgb(43, 43, 43);)

    How could I isolate the last cell item and add the png only when the row is selected?

    Any help greatly appreciated

    qtablewidget.jpg

    JonBJ 1 Reply Last reply
    0
    • alomA alom

      I'm trying to add a white triangle in the selected row of a QTableWidget to the last table item.
      currently i'm achieving this by setting a style sheet:

      QTableView::item:selected
      {
          color: rgb(222, 105, 89);
          background: rgb(43, 43, 43);
          outline: none;
          background-image:url('ui/table_item_selected.png');
          background-repeat: no-repeat;
          background-position: center right;
      }
      

      Unfortunately, this also adds the png file to the other items in the selected row.

      I've tried to add a dynamic property to the last item using setProperty(), to use another stylesheet setting, but i get a:

      AttributeError: 'PySide2.QtWidgets.QTableWidgetItem' object has no attribute 'setProperty'
      

      I've also tried to use

      image = QtGui.QPixmap('ui/main_nav_selected.png')
      tb_item.setBackground(QtGui.QBrush(image))
      

      but that repeats the image on the last cell and seems to conflicts with my style sheet for the selected row (as i'm using background: rgb(43, 43, 43);)

      How could I isolate the last cell item and add the png only when the row is selected?

      Any help greatly appreciated

      qtablewidget.jpg

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

      @alom
      setProperty is a method of QObject, https://doc.qt.io/qt-5/qobject.html#setProperty. QTableWidgetItem is not a QObject, so you can't use it on that.

      1 Reply Last reply
      0
      • alomA Offline
        alomA Offline
        alom
        wrote on last edited by alom
        #3

        @JonB Thanks that makes sense

        @Denni-0 I'm not sure I follow you.
        How can we explicitly set the image swap on only the last cell? Keep in mind the table is expandable so i cant make an image the size of the row.

        I saw that there is a setIcon() on the QTablweWidgetItem that places the image not tiled, but i cant seem to find a way to align it to the right :/

        I have a working hacky solution atm... I added a new column on the right and replaced the item for a QLable. That way I can set a dynamic property on it. I then have a callback every time currentCellChanged() to manage the current selection and update the dynamic property of each rows QLable. I have to load the style sheet every table change though.... Any better solutions??

        QTableHack.jpg

        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