Results 1 to 8 of 8

Thread: setCellWidget for every row

  1. #1
    Join Date
    Feb 2008
    Posts
    16
    Thanks
    3

    Default setCellWidget for every row

    I have a table with 5 columns and many rows. Now, is there a way to set a Widget for the first column in the table, but for all of its rows, without iterating through all of the rows and setting the widget with setCellWidget(..)?

    And one more, I couldn't figure a way to findout when an editing is started in certain cell? Thanks

  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: setCellWidget for every row

    Quote Originally Posted by gemidjy View Post
    I have a table with 5 columns and many rows. Now, is there a way to set a Widget for the first column in the table, but for all of its rows, without iterating through all of the rows and setting the widget with setCellWidget(..)?
    No, you will have to instantiate as many widgets as there are rows anyway. You can't set the same widget in multiple cells. Anyway, what does this cell widget do? Keep in mind that they are expensive to maintain and that flooding your view full of them makes the model-view framework useless.

    And one more, I couldn't figure a way to findout when an editing is started in certain cell?
    Just curious, what do you need that information for? It's the delegate who creates the editor.
    J-P Nurmi

  3. #3
    Join Date
    Feb 2008
    Posts
    16
    Thanks
    3

    Default Re: setCellWidget for every row

    Quote Originally Posted by jpn View Post
    No, you will have to instantiate as many widgets as there are rows anyway. You can't set the same widget in multiple cells. Anyway, what does this cell widget do? Keep in mind that they are expensive to maintain and that flooding your view full of them makes the model-view framework useless.


    Just curious, what do you need that information for? It's the delegate who creates the editor.
    As a matter of fact, I am in a delicate situation now. I need to use QTableWIdget to insert new data in a database. I think that it is better to use widget instead of QTableView on which a model is installed since everytime the dialog is created, an empty set in the table should appear (and if I use view/model the existent data would be shown except If I don't use filters and proxies...So, every time new data would go in the tablewidget and then commit to the database...thus, I need completion of data from within the cells, so that it reads existent records from the database and offer auto-completion (via QCompleter)

    If you have any better idea than this, I think that I would gladly use it since this is, as you said, very expensive idea.

  4. #4
    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: setCellWidget for every row

    So, what do cell widgets have to do with this scenario?
    J-P Nurmi

  5. #5
    Join Date
    Feb 2008
    Posts
    16
    Thanks
    3

    Default Re: setCellWidget for every row

    Quote Originally Posted by jpn View Post
    So, what do cell widgets have to do with this scenario?
    To set a completer I have to set it in a cell, but I can't get the cell as *widget on which I can install the Completer, right?

  6. #6
    Join Date
    Feb 2008
    Posts
    16
    Thanks
    3

    Default Re: setCellWidget for every row

    Maybe the best solution is if I could make the view not show any data until new is inserted, and then after I press a key to get it "unvisible" too....

  7. #7
    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: setCellWidget for every row

    Quote Originally Posted by gemidjy View Post
    To set a completer I have to set it in a cell, but I can't get the cell as *widget on which I can install the Completer, right?
    The item delegate is responsible for creating an editor widget every time editing begins. There are no widgets when the view is in non-editing state. This is what makes the view so light-weight. What you should do is to subclass QItemDelegate, reimplement createEditor(), call base class implementation to create the editor, try casting it as QLineEdit and install a completer if appropriate.
    J-P Nurmi

  8. #8
    Join Date
    Feb 2008
    Posts
    16
    Thanks
    3

    Default Re: setCellWidget for every row

    ahm...will take your advice..thanks!

Similar Threads

  1. Replies: 10
    Last Post: 9th July 2007, 22:02

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.