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. Set background color questions
QtWS25 Last Chance

Set background color questions

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 514 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
    Jiachen
    wrote on 15 Feb 2019, 22:08 last edited by
    #1

    I want to set the background color of QTableWidgets in Qt5 using python, the code is ( self.people_table.setItem(count,j,QtWidgets.QTableWidgetItem()) self.people_table.item(count, j).setBackground(QtGui.QColor(167, 89, 109)), but it overwritten the original values. Can anyone help?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 15 Feb 2019, 22:11 last edited by
      #2

      Hi and welcome to devnet,

      Please us coding tags to display your code properly.

      Your question is not clear.

      What gets overwritten ?
      What do you expect ?
      What do you get ?

      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
      1
      • J Offline
        J Offline
        Jiachen
        wrote on 15 Feb 2019, 22:20 last edited by
        #3

        Hi, thanks for replying, people_table is a table, count is the row index and j is the column index. What I want to do is to set the background color in the cell at index (count j) and at the same time maintains the original text in the cell, but what I get is only the color. Text has been covered by the background color.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jiachen
          wrote on 15 Feb 2019, 22:30 last edited by
          #4

          0_1550269561142_Screen Shot 2019-02-15 at 5.25.11 PM.png

          Starting from 217, what's before is writing text onto the table.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 15 Feb 2019, 22:46 last edited by
            #5

            Are you sure the text is not simply not contrasted enough to be properly seen ?

            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
            • J Offline
              J Offline
              Jiachen
              wrote on 15 Feb 2019, 22:55 last edited by
              #6

              I got it now, I just deleted line 222 and it works.

              Thank you!

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 15 Feb 2019, 23:21 last edited by
                #7

                Indeed... You were replacing the item before modify its background.

                Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

                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
                1

                1/7

                15 Feb 2019, 22:08

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved