Creating a table editor
d2uriel last edited by
Dear Qt programmers and developers,
I'm creating (as some of you already noticed ;-) ) a table editing application. Everything went almost perfect up to this moment. You guys helped me a lot along the way but I guess I need to bother you some more. I'm starting to think that what I'm trying to do is not possible with choices I've made. I'd like to ask for a piece of advice.
My editor should be capable of:
- Managing table size (row and column count along with their heights and widths),
- Allowing removing and adding of rows/columns,
- Allowing cell spanning,
- Changing font properties (bold, italics, underline, color, etc.),
- Changing background color,
/* Everything works up to this point */
- Changing border style <- this is the point I got stuck at.
I'm inheriting QTableWidget class to do the stuff I mentioned above. It seems though, that I cannot use it to modify the borders of the table. I know I can hide/show the grid - but that works for the whole grid, not parts of it. I can use styles to modify the looks of a single cell but then it's going to have an "internal" border along with the grid (which will look awful). I would actually like to paint the grid itself the way I want it to be painted (i.e. only a border around the whole table and no borders inside).
My whole concept is being ruined now. I've put a lot of work in this project and now it seems I'm in a dead end. I'm not really a professional programmer so it really takes some time to program and learn Qt framework (which, as a side note, is really great).
My question is: should I inherit from QAbstractItemView class and create my own table view class which painting I can adapt to my own needs? Or maybe there is an elegant way of using QTableWidget to actually modify the grid?
Your help is greatly appreciated.
joonhwan last edited by
If I wew you, I would first try to read QTableView:paintEvent() implementation, which will give you quite lots of hint
d2uriel last edited by
Umm... if I guessed your hint correctly - here it is:
@option.rect = QRect(colp + (showGrid && rightToLeft ? 1 : 0), rowY, colw, rowh);@
What it means is that if I will not paint the grid then all the cells will be closer together. Is that what you were suggesting?
Edit: not really... still playing around with it.
Edit #2: I managed to paint my own grid for the table. Now I need to solve some issues when painting cells. When I call the default paint() method of QStyledItemDelegate the QStyleOptionViewItem contains invalid coordinates. Take a look at the image:
As you can see the selection is being painted not exactly where it should. But I guess I'm going to manage fixing that. If not, I'll post here again.