I'm trying to code a simple c++ IDE based on Qt. Like any language IDE, a line number is very useful in the code editor.
I'm using QTreeView
for the editor and I'd like to add this line number feature in. Looks like QTreeView::header()
only returns the Horizontal header to me. How can I get the vertical header to set the line number in QAbstractItemModel::headerData()
?
There isn't a vertical header. If you're set on using QTreeView
in this way, you will need to treat the line numbers as column data associated with each item in your data model (presumably derived from QAbstractItemModel
). Each time a line is inserted, you will have to walk through your data model and update the line number associated with each data item that comes after the inserted line.
Before going too far down this path, I would download the source code for QtCreator and look at how its file editor widget is built.