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. How can I change the color and font of "QListWidgetItem" dynamically?

How can I change the color and font of "QListWidgetItem" dynamically?

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 544 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.
  • Z Offline
    Z Offline
    Zbigniew-Sch
    wrote on last edited by
    #1
    This post is deleted!
    jsulmJ 1 Reply Last reply
    0
    • Z Zbigniew-Sch

      This post is deleted!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Zbigniew-Sch said in How can I change the color and font of "QListWidgetItem" dynamically?:

      but later I can't change the parameters.

      Why not?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zbigniew-Sch
        wrote on last edited by
        #3
        This post is deleted!
        JonBJ 1 Reply Last reply
        0
        • Z Zbigniew-Sch

          This post is deleted!

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

          @Zbigniew-Sch
          It should change. Show where you call the update from, how we know which item pcoListItem-> points to and the values for font/color which are clearly different from what they presently are.

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            Zbigniew-Sch
            wrote on last edited by
            #5

            Everything is correct, but I can't change the color and font:

            QListWidgetItem* pcoListItem = this->item(0);
            pcoListItem->setFont(font());
            pcoListItem->setForeground(Qt::black);

            I created item with blue color (display is correct)
            If I set "pcoListItem->setData(Qt::ItemDataRole::UserRole + 1, "XXXX");"
            then everything works correctly but the file path for this item is not correct

            1 Reply Last reply
            0
            • JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              It is possible values from the data()/setData() methods in the model override your explicit attempts to set values, I do not know.

              setData(Qt::ItemDataRole::UserRole + 1, "XXXX");

              Qt widgets does not use UserRole + 1 for anything by default. It looks like you are using this, somehow/somewhere. What do you mean "then everything works correctly", how does changing the value for UserRole + 1 affect the font and the color? What is "XXXX"?

              I created item with blue color (display is correct)

              And did you do that via a call to setForeground() or via data()/setData() code? How should we know?

              but the file path for this item is not correct

              What "file path"? QListWidgetItem does not use "file paths" for anything.

              Maybe you need to await someone else who can understand what you are saying.

              1 Reply Last reply
              1
              • Z Offline
                Z Offline
                Zbigniew-Sch
                wrote on last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  Zbigniew-Sch
                  wrote on last edited by
                  #8
                  This post is deleted!
                  JonBJ 1 Reply Last reply
                  0
                  • Z Zbigniew-Sch

                    This post is deleted!

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

                    @Zbigniew-Sch
                    Assuming you don't get an answer from someone on the information you have provided, I think you need to post a minimal example of complete, runnable code which goes wrong for people to look at.

                    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