Results 1 to 16 of 16

Thread: Timetable Widget

  1. #1
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Lightbulb Timetable Widget

    Hi,

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



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

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Timetable Widget

    Use a simple QTableView/QTableWidget.

  3. #3
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Timetable Widget

    Quote Originally Posted by Lykurg View Post
    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.

  4. #4
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Timetable Widget

    Anyone knows how to multi select cells without pressing Ctrl?

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Timetable Widget

    Try playing with QAbstractItemView::SelectionMode and see which mode meets your needs.

  6. #6
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Timetable Widget

    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.
    It's nice to be important but it's more important to be nice.

  7. #7
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Timetable Widget

    Quote Originally Posted by axeljaeger View Post
    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!

  8. #8
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Timetable Widget

    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.

  9. #9
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: Timetable Widget

    You can use QAbstractItemView::clicked(const QModelIndex &) signal to connect to your custom slot.

  10. #10
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Timetable Widget

    Quote Originally Posted by saa7_go View Post
    You can use QAbstractItemView::clicked(const QModelIndex &) signal to connect to your custom slot.
    Thanks for your reply. I will work on it.

  11. #11
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Timetable Widget

    Single selection of QModelIndex is alright for me now. However, I'm wondering how can I use QAbstractItemView::selectedIndexes () const [virtual protected] 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?
    Last edited by sheeeng; 27th July 2010 at 09:46.

  12. #12
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: Timetable Widget

    Quote Originally Posted by sheeeng View Post
    Single selection of QModelIndex is alright for me now. However, I'm wondering how can I use QAbstractItemView::selectedIndexes () const [virtual protected] to get the list of multiple selected cells' QModelIndexes?
    You can access selected indexes through QAbstractItemView::selectionModel().

    Qt Code:
    1. tableView->selectionModel()->selectedIndexes();
    To copy to clipboard, switch view to plain text mode 
    Last edited by saa7_go; 27th July 2010 at 13:35. Reason: updated contents

  13. #13
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Timetable Widget

    Quote Originally Posted by saa7_go View Post
    You can access selected indexes through QAbstractItemView::selectionModel().

    Qt Code:
    1. tableView->selectionModel()->selectedIndexes();
    To copy to clipboard, switch view to plain text mode 
    Call the selectedIndexes() method after some event from MainWindow (that contains the tableView)?

  14. #14
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: Timetable Widget

    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().
    Last edited by saa7_go; 27th July 2010 at 15:02. Reason: updated contents

  15. #15
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Timetable Widget

    Quote Originally Posted by saa7_go View Post
    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.

  16. #16
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Timetable Widget

    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?
    Qt Code:
    1. connect( tableView, SIGNAL(entered(const QModelIndex &) ), this, SLOT( setOnOff(const QModelIndex &) ) );
    2. connect( tableView, SIGNAL(clicked(const QModelIndex &) ), this, SLOT( setOnOff(const QModelIndex &) ) );
    To copy to clipboard, switch view to plain text mode 
    Also, how can I paint a "focus" rectangle upon mouse hover a QTableView's cell?

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. Remove widget from a QList
    By Eos Pengwern in forum Newbie
    Replies: 4
    Last Post: 16th October 2009, 21:25
  3. Playbutton functionality
    By uchennaanyanwu in forum Qt Programming
    Replies: 5
    Last Post: 31st July 2008, 22:29
  4. How to Open & Close a Widget ?!!
    By Fatla in forum Qt Programming
    Replies: 6
    Last Post: 13th June 2008, 20:39
  5. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.