View Full Version : Adding widgets into QStandardItem/QTableView

24th April 2014, 14:38

we want to develop a tool you can use to manage your appointments. To display the appointments of a day we use a QTableView. Now we had the idea to provide an arrow-button in an appointment.

We draw each appointment as a QStandardItem in a cell of the view. To display appoinments which take more time than the current cell in the view provides we span the neighbouring cells until the appointment fits in the resulting cell. So we could get the problem that an appointment which reaches the borders of the view (we don't show the whole day in a view, just a little time span) does not end at the time of the last cell at the border of the view, but reaches into another time span which is currently not displayed. So there should be arrow-buttons at the end of the cell indicating that this is not the end of the appointment.

Our first idea was to use QItemDelegate to paint some arrows into the cell. This worked fine, but a simple pixmap does not provide some needed interaction(e.g. tooltip, click-event). So we tried to replace the arrow pixmaps with pushbuttons to use the power of widgets for interacting with the user. The idea to create an editor widget does not work, because the editor widget will be drawn first when the user triggers an edit event (e.g. by a double click). We already need the widget when the appointments will be displayed. But we could not find a (in our mind) clean and easy way to put a widget into a cell of a QTableView. Some ways we have found on the internet described to draw the widget manually and add each needed event also manually by calculating the mouse position and so on... but this seems to me too complicated. I hope there is an easier way in QT to do this?

Best Regards