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 fill QSql row and columns with Color?
Forum Updated to NodeBB v4.3 + New Features

How to fill QSql row and columns with Color?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 440 Views 3 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.
  • A Offline
    A Offline
    Aquarius171
    wrote on last edited by
    #1

    from PyQt4.QtSql import *
    from PyQt4.QtGui import *
    from PyQt4.QtCore import *
    import sys

    app = QApplication(sys.argv)

    db = QSqlDatabase.addDatabase("QMYSQL")

    db.setHostName("localhost")
    db.setDatabaseName("incoming_mac")
    db.setUserName("root")
    db.setPassword("admingelo")
    db.open()

    projectModel = QSqlQueryModel()
    projectModel.setQuery("select * from incoming_mac_records",db)

    projectView = QTableView()
    projectView.setModel(projectModel)
    projectView.resizeColumnsToContents()

    projectView.show()
    app.exec_()

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

      Hi
      You can try
      http://doc.qt.io/qt-5/qtablewidgetitem.html#setBackgroun
      d
      Sorry its a view.
      http://www.qtcentre.org/threads/11247-how-to-color-a-cell-in-a-QTableView

      So it seems the normal is to use a delegate or via model
      http://stackoverflow.com/questions/28006382/how-to-control-qtableview-items-backgound-color

      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