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 change TableView row colors which is using QSqlQueryModel
Forum Updated to NodeBB v4.3 + New Features

How to change TableView row colors which is using QSqlQueryModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 751 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.
  • MucipM Offline
    MucipM Offline
    Mucip
    wrote on last edited by
    #1

    Hi,
    I use Tableview like below;

    QSqlQueryModel *modelDosya;
    
    modelDosya->setQuery("SELECT sira_no, dosya_ad, dosya_yol FROM dosyalar "
                                  "WHERE kaynak_sn = " + index.sibling(index.row(), 0).data().toString() + " AND prog_kod = 59 "
                                  "ORDER BY sira_no;",baglanti::mdb());
    
    
        ui->tVDosya->setModel(modelDosya);
    
    //Not working!
    modelDosya->setData(modelDosya->index(1,2),QBrush(Qt::red), Qt::BackgroundRole);
    
    

    But color is not working. I tryed
    QStandardItemModel *modelDetay;

    And color is working well.

    Any solution for "QSqlQueryModel "

    Regards,
    Mucip:)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Either subclass QSqlQueryModel and handle that role yourself or use QIdentityProxyModel and handle the color in that model rather than the SQL model.

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

      MucipM 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        Either subclass QSqlQueryModel and handle that role yourself or use QIdentityProxyModel and handle the color in that model rather than the SQL model.

        MucipM Offline
        MucipM Offline
        Mucip
        wrote on last edited by
        #3

        Dear @SGaist ,
        I couldn't undestand very well. Please could you explain little bit more?.

        Regards,
        Mucip:)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What did you not understand ?

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

          MucipM 1 Reply Last reply
          1
          • SGaistS SGaist

            What did you not understand ?

            MucipM Offline
            MucipM Offline
            Mucip
            wrote on last edited by
            #5

            Dear @SGaist ,
            Should I use QIdentityProxyModel?
            But ı could not see setModel like easy way? I do not want to fill all cells one by one.

            Regards,
            Mucip:)

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Should you ? That's up to you to decide.

              Because the method name is setSourceModel

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

              MucipM 1 Reply Last reply
              0
              • SGaistS SGaist

                Should you ? That's up to you to decide.

                Because the method name is setSourceModel

                MucipM Offline
                MucipM Offline
                Mucip
                wrote on last edited by
                #7

                Dear @SGaist ,
                Well, any sample code to use this?

                Regards,
                Mucip:)

                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  You need a proxy model like Role Mask Proxy Model. You can find an example usage here

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  2

                  • Login

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