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 force repainting of QTableWidget?

How to force repainting of QTableWidget?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 4.5k 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.
  • A Offline
    A Offline
    Alexey
    wrote on last edited by
    #1

    Hi All,
    it seems that QTableWidget skips repaint event if model data is not changed. But I use QItemDelegate and when its state is modified I want QTableWidget to be repainted. Methods update() and repaint() don't cause repaint. Any ideas how to force repaint?

    Thank you!

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

      Hi,

      What do you mean by "when its state is modified" ?

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Alexey
        wrote on last edited by
        #3

        Nothing special :) For example, QPen used in MyItemDelegate is changed.

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

          Did you try replacing the delegate with a new one with updated properties ?

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

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            You could of course simply tickle the model to emit the dataChanged signal. If you control the model, that's easy, but otherwise you can still do it. Are you using Qt 4 or 5?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Alexey
              wrote on last edited by
              #6

              [quote author="SGaist" date="1380534014"]Did you try replacing the delegate with a new one with updated properties ?[/quote]

              I will try, but may be there is another solution...

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Alexey
                wrote on last edited by
                #7

                [quote author="Andre" date="1380534699"]You could of course simply tickle the model to emit the dataChanged signal. If you control the model, that's easy, but otherwise you can still do it. Are you using Qt 4 or 5? [/quote]

                I use Qt 4. How can I emit dataChange signal?

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  If you use your own model, then simply add a method that emits this signal for the complete range of indices in your table. If you are using a model you'd rather not subclass, you can either use a proxy model or a hack to emit the signal. While in Qt 4 signals are protected methods (in Qt 5 they are public, that's why I asked) you cannot just call the method directly. Instead, you can abuse QMetaObject::invokeMethod to call the method.

                  You will need a pointer to the model for this to work. Normally, a delegate doesn't have this. What I do in such cases, is make sure the parent of the delegate object can only be a QAbstractItemView*, and document you must use the view you are going to install the delegete on as the parent. Via the view, you can get the pointer to the model too.

                  So, you end up with something like this:
                  @
                  if (!m_parentView) return;
                  QAbstractItemModel* model = m_parentView->model();
                  if (!model) return;

                  QModelIndex topLeft = model->index(0,0);
                  QModelIndex bottomRight = model->index(model->rowCount()-1, model->columnCount()-1);
                  QMetaObject::invokeMethod(model, "dataChanged", Q_ARG(QModelIndex, topLeft), Q_ARG(QModelIndex, bottomRight));
                  @

                  Not pretty, but it should work. I did not test this myself though.

                  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