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. [Solved] How to set color to a tableview values from the database
Forum Updated to NodeBB v4.3 + New Features

[Solved] How to set color to a tableview values from the database

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.5k 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.
  • M Offline
    M Offline
    Mittu
    wrote on last edited by
    #1

    @ Log cnn;
    QSqlQueryModel *modal=new QSqlQueryModel();
    QSqlQuery *qry=new QSqlQuery(cnn.mydb);
    qry->prepare("select *from AccessLog");
    qry->exec();
    modal->setQuery(*qry);
    ui->tableView->setModel(modal);
    qDebug()<<(modal->rowCount());
    @
    With this method i can set a QSQlQueryModels to my QTableviews.How i can set color to each row in tableview.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      clochydd
      wrote on last edited by
      #2

      To achieve alternating colours for the rows you may set

      @
      ui->tableView->setAlternatingRowColors(true);
      @

      then set the colours of Base and AlternateBase in the palette.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mittu
        wrote on last edited by
        #3

        Thanks.....

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          Does that mean that you figured out the problem? If so, Please add [solved] to the topic so everyone can see that this problem is solved. You can do that by editing your first post.

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mittu
            wrote on last edited by
            #5

            And also one method for this solution,In QtCreator UI Forms select the tablview control and change the property of styleSheet. It include the various options such as color,background color,border color etc.

            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