Results 1 to 4 of 4

Thread: QTableView and checkboxes

  1. #1
    Join Date
    Feb 2008
    Location
    South Korea
    Posts
    14
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QTableView and checkboxes

    Hi all,

    I have a QTableView where I've created my own delegate to draw checkboxes for a column. I re-implemented paint() and use drawCheck(...) inside.

    I have two problems;

    1) The checkox is not immediately accessible when I click on a cell, I have to double-click the cell to activate the editor. What can I do to make the checkbox active immediately so the the user can just click once to toggle the value?

    2) The editor becomes left-justified in the cell (see attachment). I want it to be centered just like the paint() method draws them.


    Any advice would be appreciated.

    Thanks,
    Ingemar
    Attached Images Attached Images

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTableView and checkboxes

    Hi, I'd suggest taking a look at src/gui/itemviews/qitemdelegate.cpp, especially QItemDelegate::editorEvent(). The delegate should handle check states without editors.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    ibergmark (23rd February 2008)

  4. #3
    Join Date
    Feb 2008
    Location
    South Korea
    Posts
    14
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView and checkboxes

    Quote Originally Posted by jpn View Post
    Hi, I'd suggest taking a look at src/gui/itemviews/qitemdelegate.cpp
    Shucks...I keep forgetting that I have the original source code for the framework

    I have converted recently from the Microsoft .NET framework, where if I had a problem, there was no way to find out how the framework accomplished something.
    IMHO, not only does Qt surpass .NET, but it has the added benefit of learning the framework by reading the source.

    The fact that the apps can be compiled for multiple platforms is icing on the cake

    Thanks again for a great forum!
    / Ingemar

  5. #4
    Join Date
    Feb 2008
    Location
    South Korea
    Posts
    14
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView and checkboxes

    Hi again,

    I've got everything working now with my delegate, however there is one very annoying thing that happens after a field has been updated:
    The whole view re-populates itself!

    I want to have the change commited to the database immediately so I have set my editStrategy to OnFieldChange. If I change to OnManualSubmit it works as expected.

    I looked at the original source code and the QSqlTableModel does a select() after an update when the editStrategy is OnFieldChange.

    What I'm wondering about is what happens if you use a QSqlTableModel to edit a large table? After scrolling far down the list and then edit a field, the view is re-populated and the position is lost, so you have to scroll down again
    Is it really like this, or have I missed something?

    Regards,
    / Ingemar

Similar Threads

  1. Replies: 2
    Last Post: 23rd February 2008, 02:58
  2. QTableView with a checkbox
    By maxpower in forum Qt Programming
    Replies: 17
    Last Post: 18th February 2007, 10:45

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.