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. Change cursor for a particulat column in a QTableView?

Change cursor for a particulat column in a QTableView?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.3k Views
  • 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.
  • CAD_codingC Offline
    CAD_codingC Offline
    CAD_coding
    wrote on last edited by
    #1

    Hi,
    I am using the Model/View Framework by using a QAbstractTableModel subclass and a QTableView.
    I would like to make a particular column of the QTableView have a different UI because it is the only editable column in the whole table and I would like to highlight that to the user.
    I am thinking of changing the cursor, but if there are other nicer methods then your suggestions are most welcome.
    But for now how do I change the cursor for only a particular column?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      I suggest you check with SelectionModel of view. Using this you will be able to set the color any cell to different color. You can use the setCurrentIndex of selection model to achieve some of these things. I will share you piece of code later

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dcortesi
        wrote on last edited by
        #3

        Key to this is in the data() method of your table model. The table view queries this for more than just the data (Qt::DisplayRole). In particular for every cell the view queries data() for the Qt::BackgroundRole and you can return a QBrush with a particular color depending on the column number.

        I don't do C++ but in Python/PyQt5 it would be something like this:

        @ def data(self, index, role) :
        global EDITABLE_COLUMN_NUMBER
        if role == Qt.BackgroundRole :
        brush = QBrush(Qt.white)
        if index.column() == EDITABLE_COLUMN_NUMBER:
        brush.setColor(Qt.yellow)
        return brush
        ...etc etc for other roles@

        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