title: How to make a fast QTableView with HTML-formatted and clickable cells?
body: <p>I'm making a dictionary program that displays word definitions in a 3-column <code>QTableView</code> subclass, as user types them, taking data from a <code>QAbstractTableModel</code> subclass. Something like that:</p>
  
  <p><a href="https://i.stack.imgur.com/fSV0b.png" rel="noreferrer"><img src="https://i.stack.imgur.com/fSV0b.png" alt="Table and user input screenshot"></a></p>
  
  <p>I want to add various formatting to the text, I'm using <code>QAbstractItemView::setIndexWidget</code> to add a <code>QLabel</code> to each cell as data comes in:</p>
  
  <p>WordView.h</p>
  
  <pre><code>#include &lt;QTableView&gt;
  
  class QLabel;
  
  class WordView : public QTableView {
      Q_OBJECT
  
  public:
      explicit WordView(QWidget *parent = 0);
  
      void rowsInserted(const QModelIndex &amp;parent, int start, int end);
  
  private:
      void insertLabels(int row);
      void removeLabels(int row);
  };
  </code></pre>
  
  <p>WordView.cpp</p>
  
  <pre><code>#include &lt;QLabel&gt;
  #include "WordView.h"
  
  WordView::WordView(QWidget *parent) :
      QTableView(parent)
  {}
  
  void WordView::rowsInserted(const QModelIndex &amp;parent, int start, int end) {
      QTableView::rowsInserted(parent, start, end);
  
      for (int row = start; row &lt;= end; ++row) {
          insertLabels(row);
      }
  }
  
  void WordView::insertLabels(int row) {
      for (int i = 0; i &lt; 3; ++i) {
          auto label = new QLabel(this);
          label-&gt;setTextFormat(Qt::RichText);
          label-&gt;setAutoFillBackground(true);
          QModelIndex ix = model()-&gt;index(row, i);
          label-&gt;setText(model()-&gt;data(ix, Qt::DisplayRole).toString()); // this has HTML
          label-&gt;setWordWrap(true);
          setIndexWidget(ix, label); // this calls QAbstractItemView::dataChanged
      }
  }
  </code></pre>
  
  <p>However, this is very slow - it takes around 1 second to refresh 100 rows (remove all, then add 100 new ones) like that. With original QTableView it worked fast, but I did not have formatting and ability to add links (cross-references in dictionary). <strong>How to make this much faster? Or what other widget can I use to display that data?</strong></p>
  
  <p>My requirements are:</p>
  
  <ul>
  <li>Adding/removing around 1000 rows in ~0.2s, where around 30 will be visible at once</li>
  <li>Clickable, multiple internal links (<code>&lt;a&gt;</code>?) in each cell (e.g. <code>QLabel</code> has that, <code>QItemDelegate</code> might have been fast, but I don't know how to get info which link I clicked there)</li>
  <li>Formatting that allows different font sizes and colors, word wrap, different cell heights</li>
  <li>I'm not really dead-set on <code>QTableView</code>, anything that looks like a scrollable table and looks consistent with Qt graphics is okay</li>
  </ul>
  
  <p>Notes:</p>
  
  <ul>
  <li>I tried making a single label with HTML <code>&lt;table&gt;</code> instead, but it wasn't much faster. Seems like <code>QLabel</code> isn't the way to go.</li>
  <li>Data in the sample courtesy of the JMdict project.</li>
  </ul>