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. QTableView and It's Model, Decoration Role With Rectangle
Qt 6.11 is out! See what's new in the release blog

QTableView and It's Model, Decoration Role With Rectangle

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.5k 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.
  • D Offline
    D Offline
    DzCode
    wrote on last edited by DzCode
    #1

    Hi everyone,

    I know that we can put a color inside decoration role of the model.

    What about ptting a rectabgle? I want to put a rectangle inside decoration role (whose inside is empty). However decoration role cannot be a QRect. Is there any way to do it without doing inside paintevent of the qtableview custom class or inside a delegate because it is very slow when we write it inside paintevent.

    Also I need to give different color into each rectangle

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Create an image with your rectangle and return it for the decoration role.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DzCode
        wrote on last edited by
        #3

        I've just edited my description. I have assign different colors for each rectangle. So that setting an image is not a proper way for me. I have more than 1k rows with different colors.

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then create an image per color and store them in a container

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          D 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            Then create an image per color and store them in a container

            D Offline
            D Offline
            DzCode
            wrote on last edited by
            #5

            @Christian-Ehrlicher do you mean creating QPixMap?

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Decoration role accepts QPixmap, QImage, QIcon or a simple QColor - so yes create a pixmap for each color and return it accordingly.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              D 1 Reply Last reply
              2
              • Christian EhrlicherC Christian Ehrlicher

                Decoration role accepts QPixmap, QImage, QIcon or a simple QColor - so yes create a pixmap for each color and return it accordingly.

                D Offline
                D Offline
                DzCode
                wrote on last edited by
                #7

                @Christian-Ehrlicher Thank you

                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