You should look into the code editor example.
Basically you just place a widget over the viewport margin. You also have to resize your widget when you QTableView
object is resized. This of course is done in the resize event of your QTableView
object.
This is how it's done in the example:
void CodeEditor::resizeEvent(QResizeEvent *e)
{
QPlainTextEdit::resizeEvent(e);
QRect cr = contentsRect();
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
}