PDA

View Full Version : Timetable Widget



sheeeng
19th December 2009, 05:50
Hi,

How can I implement a timetable like widget on Qt as shown in the image below?

http://www.microsoft.com/library/media/1033/windows/images/windows-vista/features/screenshot_time_limits.jpg

This widget allows me to select / deselect the time slot.

Thanks in advance.

Lykurg
19th December 2009, 07:25
Use a simple QTableView/QTableWidget.

sheeeng
19th December 2009, 08:30
Use a simple QTableView/QTableWidget.

Thanks for pointing out the relevant Qt classes, Lykurg. Which class is better to be use in my case, QTableView or QTableWidget? Would like to use the simple approach in getting this done.

From the documentations, QTableWidget inherits QTableView.

So, how would I know if a user clicks on a cell (or click-drag multiple horizontal cells for longer time slots) to make the selection or deselection?

Then, I would have to alternate (or switch between a range of colors for different options, e.g. busy, tentative, and free) the colors of the cells when I receive these events.

Thanks in advance.

sheeeng
1st April 2010, 08:30
Anyone knows how to multi select cells without pressing Ctrl?

aamer4yu
1st April 2010, 09:39
Try playing with QAbstractItemView::SelectionMode and see which mode meets your needs.

axeljaeger
3rd April 2010, 15:57
I always suggest to use the Q*View instead of the Q*Widget-classes. The difference is that the *Widget come with their own model, for the *View, you have to write the model yourself.
BUT: In the end, the model provides your business logic. If you use the standard model that is provided by Qt, you will not be able to use most of the features of their model-view framework.

sheeeng
7th April 2010, 04:37
I always suggest to use the Q*View instead of the Q*Widget-classes. The difference is that the *Widget come with their own model, for the *View, you have to write the model yourself.
BUT: In the end, the model provides your business logic. If you use the standard model that is provided by Qt, you will not be able to use most of the features of their model-view framework.

Thanks for the explanation!

sheeeng
27th July 2010, 03:10
Let's say my model subclassed from QAbstractTableModel.

I'm implementing my data structure as QList<QList<bool>>.

I'm using the normal QTableView, not a custom widget.

How do I usethe onClick event of a cell to change the bool value in that particular cell?

Thanks in advance.

saa7_go
27th July 2010, 04:22
You can use QAbstractItemView::clicked(const QModelIndex &) (http://doc.trolltech.com/4.6/qabstractitemview.html#clicked) signal to connect to your custom slot.

sheeeng
27th July 2010, 04:30
You can use QAbstractItemView::clicked(const QModelIndex &) (http://doc.trolltech.com/4.6/qabstractitemview.html#clicked) signal to connect to your custom slot.

Thanks for your reply. I will work on it.

sheeeng
27th July 2010, 09:16
Single selection of QModelIndex is alright for me now. However, I'm wondering how can I use QAbstractItemView::selectedIndexes () const [virtual protected] (http://doc.trolltech.com/latest/qabstractitemview.html#selectedIndexes) to get the list of multiple selected cells' QModelIndexes? Should I should use QAbstractItemDelegate?
E.g. multiple selection cells using Ctrl - Left mouse click / Shift / Left mouse click and drag to select cells?

saa7_go
27th July 2010, 13:35
Single selection of QModelIndex is alright for me now. However, I'm wondering how can I use QAbstractItemView::selectedIndexes () const [virtual protected] (http://doc.trolltech.com/latest/qabstractitemview.html#selectedIndexes) to get the list of multiple selected cells' QModelIndexes?

You can access selected indexes through QAbstractItemView::selectionModel() (http://doc.trolltech.com/4.6/qabstractitemview.html#selectionModel).


tableView->selectionModel()->selectedIndexes();

sheeeng
27th July 2010, 14:51
You can access selected indexes through QAbstractItemView::selectionModel() (http://doc.trolltech.com/4.6/qabstractitemview.html#selectionModel).


tableView->selectionModel()->selectedIndexes();

Call the selectedIndexes() method after some event from MainWindow (that contains the tableView)?

saa7_go
27th July 2010, 15:00
Maybe, yes.... I don't understand with "after some event from MainWindow".
For example, if you have a pushbutton, you connect it's clicked() signal to your pusbutton_clicked() slot, then in your pushbutton_clicked() function you called selectedIndexes().

sheeeng
27th July 2010, 15:03
Maybe, yes.... I don't understand with "after some event from MainWindow".
For example, if you have a pushbutton, you connect it's clicked() signal to your pusbutton_clicked() slot, then in your pushbutton_clicked() function you called selectedIndex().

Thanks for the tips! Single click on a single cell is alright for me now. I would like to perform multiple cells selection and update the value.

sheeeng
27th July 2010, 16:26
I did tried to use the code below to make left-click drag and multiple selection of cells. It works with multiple selection. However, I cannot make entered() and clicked() mutually exclusive to each other for a cell. It triggers double events called when clicked and the reverted the value. Any other approaches?


connect( tableView, SIGNAL(entered(const QModelIndex &) ), this, SLOT( setOnOff(const QModelIndex &) ) );
connect( tableView, SIGNAL(clicked(const QModelIndex &) ), this, SLOT( setOnOff(const QModelIndex &) ) );

Also, how can I paint a "focus" rectangle upon mouse hover a QTableView's cell?