1

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()?

zhongzhu
  • 307
  • 2
  • 4
  • 14
  • 2
    Why would you be using `QTreeView` for the editor control? Shouldn't that be a `QTextEdit`? – sashoalm Nov 30 '12 at 08:16
  • `QTreeView` doesn't have a vertical header. – ecatmur Nov 30 '12 at 09:05
  • I'm creating a "new language", which is like C++ but much simpler. Since its grammar is simple enough, I'd like people to write code in a treeview widget. – zhongzhu Nov 30 '12 at 09:23
  • QTreeView doesn't have a vertical header? That's bad news. – zhongzhu Nov 30 '12 at 09:24
  • Here you can use similar approach -- [SO: Adding Vertical headers to a `QTreeView`][1]. Good luck! [1]: http://stackoverflow.com/questions/1967210/adding-vertical-headers-to-a-qtreeview – NG_ Nov 30 '12 at 11:25

1 Answers1

1

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.

Penn Taylor
  • 362
  • 2
  • 9
  • thank you Penn! that works for me.Just need to tune the column color to make it more like a vertical header. – zhongzhu Dec 01 '12 at 03:27