Results 1 to 4 of 4

Thread: QTableView, editable, 3 columns: QString, QWidget and QWidget

  1. #1
    Join Date
    Dec 2009
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QTableView, editable, 3 columns: QString, QWidget and QWidget

    I'm trying to have an editable table of entries. Each entry has 3 columns.

    The 1st is a choice of a string among a dynamic list of strings. So graphically, it should be a "pull-down menu"

    The 2nd is, for the select string from the 1st column, there is a list of fields, values. I have a function that returns a QWidget that is made of QLabels and QLineEdits. I would like this QWidget to be in the 2nd column.

    The 3rd column is a file path in a QLineEdit with a QPushButton.

    The whole table is editable.

    This QTableView uses a class derived from QAbstractTableModel. However I am unable to return QWidgets from the
    Qt Code:
    1. QVariant data(const QModelIndex& index, int role) const
    To copy to clipboard, switch view to plain text mode 
    function.

    What should I use when the cells of the table are complex widgets?

    Regards,

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

    Default Re: QTableView, editable, 3 columns: QString, QWidget and QWidget

    You have to use delegates for that. See "Delegate Classes" and/or "An Introduction to Model/View Programming" in the documentation for a first start.

  3. #3
    Join Date
    Dec 2009
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView, editable, 3 columns: QString, QWidget and QWidget

    Thanks,

    I am writing the
    Qt Code:
    1. QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
    2. const QModelIndex &index) const;
    To copy to clipboard, switch view to plain text mode 
    function of the delegate.

    Column 0 is a non editable QComboBox where the user selects between a list of application objects represented by QStrings.
    Columm 1 is an editable QWidget with (QLabels and QLineEdits). This cell depends on what is selected in the QComboBox.

    There can be a different selection in the QComboBox for each row, of course.

    This is the start of the implementation of createEditor:
    Qt Code:
    1. {
    2. switch(index.column()) {
    3. case 0: {
    4. QComboBox* systems_widget = new QComboBox(this); /// check parenting is ok
    5. systems_widget->setEditable(false);
    6. for (....) /// pseudo code here
    7. systems_widget->addItem( QString(someStdString.c_str()) );
    8. }
    9. return systems_widget;
    10. }
    11. case 1:
    12. return .... /// How do I pick up the selected item from the QComboBox in column 0 ?
    13. case 2:
    14. /// to implement
    15. default:
    16. return 0;
    17. };
    18. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Dec 2009
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView, editable, 3 columns: QString, QWidget and QWidget

    Hello,

    My QTableView is basically in Edit mode all the time.
    The
    Qt Code:
    1. createEditor
    To copy to clipboard, switch view to plain text mode 
    returns a widget that is placed on top of the display widget for each cell when editing.
    I don't need this.
    Can I reuse the normal display widget (is there a default one?)

    Rds,

Similar Threads

  1. Replies: 13
    Last Post: 7th March 2013, 09:10
  2. Promoting the parent QWidget of a QWidget form
    By extrakun in forum Qt Tools
    Replies: 6
    Last Post: 16th April 2010, 14:19
  3. Focus on a QWidget item in a QWidget
    By vycke in forum Qt Programming
    Replies: 10
    Last Post: 7th January 2008, 21:00
  4. QWidget::exec() and QWidget::show()
    By MarkoSan in forum Qt Programming
    Replies: 6
    Last Post: 18th October 2007, 21:39
  5. Replies: 1
    Last Post: 2nd May 2006, 21:11

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.