There are a couple of ways to implement this. It all depends on how you want to use the grid.
For widgets to be painted, they need to be a subclass of QWidget. You implement the paint event to do the actual painting.
But, you do not have to add widgets. You can paint an svg, or bmp and use events to handle mouse clicks etc... But that will be more work than just subclassing a QWidget I guess.
My opinion:
One way is to use model/view:
- Advantages: table based models and views are readily available.
- Disadvantages: might be too complex for a basic grid. I guess you only need to write a delegate to paint the widgets in each cell. Maybe a simple custom table model.
Another way is to use QGraphicsView:
- Advantages: easier to include widgets
- Disadvantages: might take more work to handle the grid widgets.
A third way is to use layouts:
- Advantages: easy to include widgets
- Disadvantages: might take more work to handle the grid widgets.
Bookmarks