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. QTableWidget - How to set background-color with widget
Forum Updated to NodeBB v4.3 + New Features

QTableWidget - How to set background-color with widget

Scheduled Pinned Locked Moved General and Desktop
12 Posts 2 Posters 13.9k 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.
  • S SGaist
    18 Sept 2015, 19:56

    Hi,

    Can you share the code you use to setup the background color and widgets ?

    F Offline
    F Offline
    fgdevel
    wrote on 22 Sept 2015, 14:52 last edited by
    #3

    @SGaist

    yes of course :

    [...]
    tableItem = new QTableWidgetItem("");
    tableItem->setFlags(tableItem->flags() & ~(Qt::ItemIsEditable));
    //Add Table items here With Default Cell Texts
    ui->tableWidget->setItem(y,0,new QTableWidgetItem(""));
    ui->tableWidget->setItem(y,1,tableItem);
    ui->tableWidget->setItem(y,2,new QTableWidgetItem(""));
    ui->tableWidget->setCellWidget(y,3,new QCheckBox(""));
    ui->tableWidget->setCellWidget(y,4,new QCheckBox(""));
    ui->tableWidget->setCellWidget(y,5,new QCheckBox(""));
    [...]

    The background-color works only for "QTableWidgetItem" cells (without widget)

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 22 Sept 2015, 15:00 last edited by
      #4

      When you set a cell widget you don't see the item underneath (and you don't have any under), you have to set the background on the widget itself.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      F 1 Reply Last reply 22 Sept 2015, 15:10
      0
      • S SGaist
        22 Sept 2015, 15:00

        When you set a cell widget you don't see the item underneath (and you don't have any under), you have to set the background on the widget itself.

        F Offline
        F Offline
        fgdevel
        wrote on 22 Sept 2015, 15:10 last edited by fgdevel
        #5

        @SGaist

        is there any global function to set the background-color ? (which works with or without widget...) ?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 22 Sept 2015, 15:11 last edited by
          #6

          You can try by modifying the palette of the application.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          F 1 Reply Last reply 22 Sept 2015, 15:16
          0
          • S SGaist
            22 Sept 2015, 15:11

            You can try by modifying the palette of the application.

            F Offline
            F Offline
            fgdevel
            wrote on 22 Sept 2015, 15:16 last edited by
            #7

            @SGaist

            I want to modify a specific TableWidget and not all grids or all widget contained in the application...Have you an example ?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 22 Sept 2015, 19:55 last edited by
              #8

              You want to modify only that widget and all its children ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              F 1 Reply Last reply 24 Sept 2015, 09:34
              0
              • S SGaist
                22 Sept 2015, 19:55

                You want to modify only that widget and all its children ?

                F Offline
                F Offline
                fgdevel
                wrote on 24 Sept 2015, 09:34 last edited by
                #9

                @SGaist

                I want to modify all cells of QTableWidget, several cells contain QTableWidgetItem, several cells contain QCheckbox for example

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 24 Sept 2015, 19:26 last edited by
                  #10

                  Then you can write the style sheet so that it applies to both your QTableWidget and its children widgets

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  F 1 Reply Last reply 9 Oct 2015, 16:02
                  0
                  • S SGaist
                    24 Sept 2015, 19:26

                    Then you can write the style sheet so that it applies to both your QTableWidget and its children widgets

                    F Offline
                    F Offline
                    fgdevel
                    wrote on 9 Oct 2015, 16:02 last edited by
                    #11

                    @SGaist

                    It seems to work on QTableWidget but not on children widgets when I set the style sheet

                    F 1 Reply Last reply 9 Oct 2015, 16:16
                    0
                    • F fgdevel
                      9 Oct 2015, 16:02

                      @SGaist

                      It seems to work on QTableWidget but not on children widgets when I set the style sheet

                      F Offline
                      F Offline
                      fgdevel
                      wrote on 9 Oct 2015, 16:16 last edited by
                      #12

                      I have resolved my problem with :

                      ui->tableWidget->item(i,j)->setBackground(Qt::gray);

                      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