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. Changing the value of DecorationRole Value in QTreeView on the fly

Changing the value of DecorationRole Value in QTreeView on the fly

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.0k 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    Hi
    I have a QtreeView and I am displaying colored rectangle images in the first column for each row in QTreeView . The requirement in when the user clicks on the colored rectangle a QColorDialog comes up and then when the picks the color and sets ok then the colored rectangle should change .Can someone guide me on this

    The code is something like this
    QVariant myModel::data(const QModelIndex& index, int role) const
    {
    switch (role) {
    case Qt::DecorationRole:
    if (index.column() == 1) {
    QPixmap cellPixmap(QSize(10,10));
    QColor sc = GQUtil::getStandardColor(index.row());

      cellPixmap.fill(sc);
      QIcon icon(cellPixmap);
      return icon;
    }
    

    }

    1 Reply Last reply
    0
    • P Offline
      P Offline
      panosk
      wrote on last edited by
      #2

      Hi,
      You probably have to reimplement setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) and define the color for the Qt::DecorationRole in there.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        If you write a small code , it will be helpful

        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