Results 1 to 4 of 4

Thread: EXAMPLE:Trying to understand model/view with QTableView!!!

  1. #1
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: EXAMPLE:Trying to understand model/view with QTableView!!!

    well, I have read some tens of times most tutorials,posts and examples. I think I have understood most of the functions and classes, but I fail to put all these together.

    I am looking for a very simple example:

    a tableview with just 1 row and 2 columns, just two boxes.
    One box should be a widget-qcombobox and the other just normal box to insert a string.

    Now, I want to connect the database of the tableview with a QLineEdit (let's call it resultLineEdit) every time a new value is inserted by the user.

    Can you give me a piece of code to start with?


    Added after 1 58 minutes:


    i started like this:

    Qt Code:
    1. class M : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. M(QWidget *parent = 0);
    7.  
    8.  
    9. private:
    10. QTableView *table;
    11.  
    12. QLineEdit * resultEdit;
    13. QPushButton *quit;
    14.  
    15. };
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. M::M(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. int r = 2,c = 2;
    5.  
    6. model = new QStandardItemModel(r,c);
    7. table = new QTableView();
    8. table->setModel(model);
    9.  
    10. for (int row = 0; row < r; ++row) {
    11. for (int column = 0; column < c; ++column) {
    12. QStandardItem *item = new QStandardItem(QString("iii"));
    13. model->setItem(row,column,item);
    14. }
    15. }
    16.  
    17. resultEdit = new QLineEdit;
    18. resultEdit->setText("results here....");
    19. quit = new QPushButton;
    20. quit->setText("quit!");
    21. connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
    22. QVBoxLayout *mainLayout = new QVBoxLayout();
    23. mainLayout->addWidget(resultEdit);
    24. mainLayout->addWidget(quit);
    25. mainLayout->addWidget(table);
    26. setLayout(mainLayout);
    27. }
    To copy to clipboard, switch view to plain text mode 

    the question is:
    how can I connect the the changes of any item of the table to the slot setText(QString) of the resultEdit?
    Last edited by fatecasino; 22nd February 2011 at 19:22.

  2. #2
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: EXAMPLE:Trying to understand model/view with QTableView!!!

    Is it a combination of the following?

    QItemSelectionModel
    QModelIndex
    Qt:: DisplayRole


    any small code example would be really helpful!

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: EXAMPLE:Trying to understand model/view with QTableView!!!

    QTableView is not really fit for what you want. I would rather use QDataWidgetMapper. It uses widgets to display data from a model. QTableView doesn't.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: EXAMPLE:Trying to understand model/view with QTableView!!!

    just to understand,
    do you mean that if I generally want to display/use the data from the model/view architecture I have to use QDataWidgetMapper? What I really want to do is the user to set some parameters to plot a scientific diagram through qwt. The user would inserts these values (boxes and qcomboboxes) and if necessary s/he would add a new row and insert more (it's a complex curve fitting problem)
    Attached Images Attached Images

Similar Threads

  1. Replies: 1
    Last Post: 1st February 2010, 18:42
  2. Replies: 1
    Last Post: 18th November 2009, 23:21
  3. QTableView - model / view pattern - layout, edit
    By vlastagf in forum Qt Programming
    Replies: 4
    Last Post: 1st August 2009, 22:42
  4. Model/View framework: streaming data in a QTableView
    By yannickt in forum Qt Programming
    Replies: 6
    Last Post: 24th October 2008, 00:06
  5. Replies: 9
    Last Post: 7th November 2006, 15:10

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.