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. QStyledItemDelegate - Update paint after state change
Forum Updated to NodeBB v4.3 + New Features

QStyledItemDelegate - Update paint after state change

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 967 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.
  • H Offline
    H Offline
    hbatalha
    wrote on last edited by
    #1

    I have delegate button that I will be changing its state through a function like this:

    void MyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
        QStyleOptionButton button;
        QRect r = option.rect;//getting the rect of the cell
        int x,y,w,h;
        x = r.center().x() - 10;//the X coordinate
        y = r.top();//the Y coordinate
        w = 20;//button width
        h = 20;//button height
        button.rect = QRect(x,y,w,h);
        button.text = "";
        
        if(isEnabled)
            button.state = QStyle::State_Enabled;
        else
            button.state &= ~QStyle::State_Enabled;
    
        QApplication::style()->drawControl( QStyle::CE_PushButton, &button, painter);
        QItemDelegate::paint(painter, option, index);
    }
    
    void MyDelegate::setEnable(bool enabled)
    {
        isEnabled = enabled;
    }
    

    After calling setEnable() the state doesn't change(visually) immediately like I desire it to. I was hoping for a update() -like function but I found no such.
    So I am wondering how to do that.

    eyllanescE 1 Reply Last reply
    0
    • H hbatalha

      I have delegate button that I will be changing its state through a function like this:

      void MyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
      {
          QStyleOptionButton button;
          QRect r = option.rect;//getting the rect of the cell
          int x,y,w,h;
          x = r.center().x() - 10;//the X coordinate
          y = r.top();//the Y coordinate
          w = 20;//button width
          h = 20;//button height
          button.rect = QRect(x,y,w,h);
          button.text = "";
          
          if(isEnabled)
              button.state = QStyle::State_Enabled;
          else
              button.state &= ~QStyle::State_Enabled;
      
          QApplication::style()->drawControl( QStyle::CE_PushButton, &button, painter);
          QItemDelegate::paint(painter, option, index);
      }
      
      void MyDelegate::setEnable(bool enabled)
      {
          isEnabled = enabled;
      }
      

      After calling setEnable() the state doesn't change(visually) immediately like I desire it to. I was hoping for a update() -like function but I found no such.
      So I am wondering how to do that.

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @hbatalha You have to call the update() method of the view.

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      H 1 Reply Last reply
      0
      • eyllanescE eyllanesc

        @hbatalha You have to call the update() method of the view.

        H Offline
        H Offline
        hbatalha
        wrote on last edited by
        #3

        @eyllanesc Thanks, I did that by:

        ui->tableWidget->viewport()->update();
        
        eyllanescE 1 Reply Last reply
        0
        • H hbatalha

          @eyllanesc Thanks, I did that by:

          ui->tableWidget->viewport()->update();
          
          eyllanescE Offline
          eyllanescE Offline
          eyllanesc
          wrote on last edited by
          #4

          @hbatalha I think ui->tableWidget->update(); should be enough.

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          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