PDA

View Full Version : Questions about Subclassing QItemDelegate



Slewman
15th February 2010, 14:04
So, I have a question about creating a subclass of the QItemDelegate... often named "MyItemDelegate"

I am trying to create a border around certain rows of my QTableWidget, would this be possible by subclassing the QItemDelegate? If yes, then how exactly would i do that?

Everything i have looked up about the QItemDelegate hints that subclassing it would only allow me to customize individual items in the table, and not the whole row. But then again, im no Qt expert and im still learning.

Please, any help would be greatly appreciated. Thanks!

Lykurg
15th February 2010, 14:52
I am not sure how we could help you. You have to subclass QItemDelegate. There is nothing to help so far. For customising you have to alter the paint method.

To see how a (more complex) subclassing works have a look at the Spin Box Delegate Example in the docs. If you than have more specific question we could help you.

Slewman
15th February 2010, 15:03
thanks ill look into the documentation.

ill try to be more specific with my question. I am trying to create a border around the rows of my QTableWidget. At the moment i dont see any way of doing that, i only see a way to create a border around the whole QTableWidget. I am just trying to create one around the rows individually... is this specific enough?

Lykurg
15th February 2010, 15:14
See QTableView::setShowGrid() and QTableView::setGridStyle(). If that is not enough for you subclass the paint method and do the painting yourself. (See the documentation to QItemDelegate::paint() there is also an example...)

toutarrive
15th February 2010, 20:58
One way could be:

- not showing the table grid,
- calculate the total length of a row,
- draw a rectangle using this length value, for each row .

As Lykurg stated, you have to subclass the QItemDelegate::paint() method to do that.

It's basically a matter of getting the correct coordinates for the drawing of you rectangle.