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. QVariant convert to QBrush
Qt 6.11 is out! See what's new in the release blog

QVariant convert to QBrush

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.6k Views 2 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.
  • C Offline
    C Offline
    ctoverend
    wrote on last edited by
    #1

    I am working with a QTreeview.
    Using:
    index_data = treeview.model.data(index, QT::ForegroundRole)
    index_data.type()
    > 66 -> QBrush
    index_data.canConvert(66)

    1
    index_data.convert(66)
    1
    So all indications are that the QVariant was converted to QBrush,
    however I am unable to call any QBrush functions on idex_data.
    I am doing all of this in Squish

    I am ultimately looking for the color of text in the index.

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

      Hi and welcome to devnet,

      you should rather use

      index_data.canConvert<QBrush>()

      then

      QBrush brush = index_data.value<QBrush>();
      //modify brush
      treeview->model()->setData(index, brush, Qt::ForegroundRole);
      

      Hope it helps

      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
      • C Offline
        C Offline
        ctoverend
        wrote on last edited by
        #3

        The color of the text is already set. I am testing that the color is correct.
        When I convert the QVariant to a QBrush I expect that I can call color()
        and verify that it was set properly. However when I convert the Qvariant to QBrush the functions available to me are those of the QVariant not QBrush. Is there a better way to get text color from an QModelIndex?

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

          QBrush brush = index_data.value<QBrush>();

          There you have your QBrush object you want to test

          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
          • C Offline
            C Offline
            ctoverend
            wrote on last edited by
            #5

            Unfortunately Squish does not allow me to use the same syntax that you are using.
            I tried multiple variations of your code all give me <type 'exceptions.AttributeError'>.
            I am contacting them. Thanks for the help.

            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