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 to hightlight certain rows in qt tablewidget?
Forum Updated to NodeBB v4.3 + New Features

how to hightlight certain rows in qt tablewidget?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 495 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 Offline
    S Offline
    small_bird
    wrote on 6 Sept 2019, 06:50 last edited by
    #1

    0_1567752387495_b606a84f-2b0f-4ff4-9775-616c7203d4b2-image.png
    hello, everyone.
    as showed in the above picture, now I want to hightlight certain lines in the table, meaning that after I click the down forward arrow in the scroll bar right in the picture, the hightlighted rows move up and when I click the up forward arrow in the scroll bar, the hightlighted rows shows again.
    how to do that? Thank in advance!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 6 Sept 2019, 06:58 last edited by
      #2

      Hi
      and this purple line should be something other than the currently
      selected row ?
      Like a color code on a row. ?

      S 2 Replies Last reply 6 Sept 2019, 07:01
      0
      • M mrjj
        6 Sept 2019, 06:58

        Hi
        and this purple line should be something other than the currently
        selected row ?
        Like a color code on a row. ?

        S Offline
        S Offline
        small_bird
        wrote on 6 Sept 2019, 07:01 last edited by small_bird 9 Jun 2019, 07:02
        #3

        @mrjj The purple line is not the selected row, it shows the mouse selecting behavior. The yellow lines is the selected rows, though just show the first column.

        1 Reply Last reply
        0
        • M mrjj
          6 Sept 2019, 06:58

          Hi
          and this purple line should be something other than the currently
          selected row ?
          Like a color code on a row. ?

          S Offline
          S Offline
          small_bird
          wrote on 6 Sept 2019, 07:07 last edited by
          #4

          @mrjj It seems like that the tablewidget can only manipulate the current showing rows.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 6 Sept 2019, 07:08 last edited by
            #5

            Ok
            so i assume you cannot just use the selection line for this.
            (it can be set to select whole row at once)

            Well you can color the items backgrounds. that also work even if
            the items are not currently shown.

            S 1 Reply Last reply 6 Sept 2019, 07:15
            0
            • M mrjj
              6 Sept 2019, 07:08

              Ok
              so i assume you cannot just use the selection line for this.
              (it can be set to select whole row at once)

              Well you can color the items backgrounds. that also work even if
              the items are not currently shown.

              S Offline
              S Offline
              small_bird
              wrote on 6 Sept 2019, 07:15 last edited by
              #6

              @mrjj ```

                  QTableWidgetItem *item1 = new QTableWidgetItem;
                   item1->setTextColor(txtColor);
                   item1->setBackgroundColor(backColor);
                   item1->setTextAlignment(Qt::AlignCenter);
                   ui->tableWidget->setItem(cnt,0,item1);
              
              it is the code, following your advice, however, no effect.
              M 1 Reply Last reply 6 Sept 2019, 07:25
              0
              • S small_bird
                6 Sept 2019, 07:15

                @mrjj ```

                    QTableWidgetItem *item1 = new QTableWidgetItem;
                     item1->setTextColor(txtColor);
                     item1->setBackgroundColor(backColor);
                     item1->setTextAlignment(Qt::AlignCenter);
                     ui->tableWidget->setItem(cnt,0,item1);
                
                it is the code, following your advice, however, no effect.
                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 6 Sept 2019, 07:25 last edited by mrjj 9 Jun 2019, 07:25
                #7

                @small_bird
                Hi
                Did you remember to adjust row/col count ?
                Work fine here

                alt text

                    ui->tableWidget->setRowCount(5);
                    ui->tableWidget->setColumnCount(5);
                
                    for (int c = 0; c < ui->tableWidget->rowCount(); c++) {
                        QTableWidgetItem *item1 = new QTableWidgetItem;
                        item1->setTextColor(Qt::red);
                        auto col = QColor( rand() % 255, rand() % 255, rand() % 255);
                        item1->setBackgroundColor( col  );
                        item1->setTextAlignment(Qt::AlignCenter);
                        ui->tableWidget->setItem(c, 0, item1);
                    }
                
                S 1 Reply Last reply 6 Sept 2019, 07:31
                1
                • M mrjj
                  6 Sept 2019, 07:25

                  @small_bird
                  Hi
                  Did you remember to adjust row/col count ?
                  Work fine here

                  alt text

                      ui->tableWidget->setRowCount(5);
                      ui->tableWidget->setColumnCount(5);
                  
                      for (int c = 0; c < ui->tableWidget->rowCount(); c++) {
                          QTableWidgetItem *item1 = new QTableWidgetItem;
                          item1->setTextColor(Qt::red);
                          auto col = QColor( rand() % 255, rand() % 255, rand() % 255);
                          item1->setBackgroundColor( col  );
                          item1->setTextAlignment(Qt::AlignCenter);
                          ui->tableWidget->setItem(c, 0, item1);
                      }
                  
                  S Offline
                  S Offline
                  small_bird
                  wrote on 6 Sept 2019, 07:31 last edited by
                  #8

                  @mrjj Thanks a lot, the problem is solved!

                  1 Reply Last reply
                  2

                  1/8

                  6 Sept 2019, 06:50

                  • Login

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