Results 1 to 16 of 16

Thread: QT Table Model

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QT Table Model

    Hello everybody

    We are using QTableModel in our program, and from that table we would like to open another window.

    We are doing the same thing for the TreeWidget by the help of the status tip, but for the table model we are not able to open another window from our table.

    We really need help for this because we are locked!!!

    Help us!

    Regards

    Efe

  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: QT Table Model

    Any QWidget without a parent is a top level widget eg. a "window". QAbstractItemView has several signals you could act upon. When do you exactly want to show the window? What is it supposed to contain?
    J-P Nurmi

  3. #3
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT Table Model

    for the tree widget we are using a signal like this in our main window

    connect(treeCariAra, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotCariEdit(QTreeWidgetItem *)));

    and void is like this in our main window.

    void slotCariEdit(QTreeWidgetItem *item)
    {
    QTreeWidgetItem *itemcari = treeCariAra->currentItem();
    if (itemcari == 0)
    return;
    formCari *ca = new formCari(this, itemcari->statusTip(0));
    ca->exec();
    return;
    }


    There is another place that we would like to reach the same data by a table model. For the Model we bring it our relatinal model like this

    QSqlRelationalTableModel *cariler = new QSqlRelationalTableModel;
    cariler->setTable("cari");
    fiyatlistecari->setEditStrategy(QSqlRelationalTableModel::OnRowCh ange);
    cariler->select();


    tableCariler->setModel(cariler);
    tableCariler->setItemDelegate(new QSqlRelationalDelegate(tableCariler));

    After we bring our model we would like to make a link like to our formCari but we dont know which slots that we should be using.

    AEK

  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: QT Table Model

    I must admit that I don't really understand why to use status tips. But anyway, you should be able to reach the same functionality by connecting to QAbstractItemView::doubleClicked() signal. You must have a view there, showing the model, right? The model is not responsible for this kind of functionality..
    J-P Nurmi

  5. #5
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT Table Model

    Please thing that i have a book window that i store my books to my database. I could see everything in a detail.

    After that in a program samewhere i list all my books on a table model that i could see all of them in a table. But i would like to double click on one of the books from the table and see its details in my book window

  6. #6
    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: QT Table Model

    Something like this should be quite close to the behavior with the tree widget:
    Qt Code:
    1. connect(tableCariler, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(slotCariEdit(const QModelIndex&)));
    2.  
    3. void slotCariEdit(const QModelIndex& idx)
    4. {
    5. formCari ca(this, idx->data(Qt::StatusTipRole).toString());
    6. ca.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    aekilic (24th January 2007)

  8. #7
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT Table Model

    Quote Originally Posted by aekilic View Post
    After that in a program samewhere i list all my books on a table model that i could see all of them in a table. But i would like to double click on one of the books from the table and see its details in my book window
    For the table model i was telling that a QRelationalTableModel not a tree widget, please help usss,

  9. #8
    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: QT Table Model

    Quote Originally Posted by aekilic View Post
    For the table model i was telling that a QRelationalTableModel not a tree widget, please help usss,
    What do you want me to do? I already gave you the example code.

    QRelationalTableModel, nor any other model handles double clicks. Model is there to provide some data for views. It's the view that handles double clicks and such. QAbstractItemView is the base class of all the views (QTreeView, QTableView, QListView) and offers a signal "doubleClicked(const QModelIndex&)" which is emitted whenever an index is double clicked in the view.

    Didn't you notice any difference between the example snippet of mine and the corresponding QTreeWidget code of yours?
    J-P Nurmi

  10. #9
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT Table Model

    i allready tried yours but i got a error like

    error:request for member 'exec' in 'ca', which is of non-class type 'formCari'

  11. #10
    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: QT Table Model

    Quote Originally Posted by aekilic View Post
    i allready tried yours but i got a error like

    error:request for member 'exec' in 'ca', which is of non-class type 'formCari'
    The only difference to your example is that I allocated the dialog on the stack. A modal dialog is one of the cases where it is acceptable to allocate a QWidget on the stack. QDialog::exec() blocks as long as the modal dialog is accepted/rejected.

    I assumed that "formCari" is a subclass of QDialog. You have used exec():
    Quote Originally Posted by aekilic View Post
    Qt Code:
    1. void slotCariEdit(QTreeWidgetItem *item)
    2. {
    3. ...
    4. formCari *ca = new formCari(this, itemcari->statusTip(0));
    5. ca->exec();
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 
    So isn't "formCari" a subclass of QDialog? Or did you just mix operators "." and "->" up or even forget an include statement?
    Last edited by jpn; 20th January 2007 at 19:06. Reason: spelling error
    J-P Nurmi

  12. #11
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT Table Model

    We have solved the problem thank you very much,

    We have tried to change some codes

    connect(tableCariler, SIGNAL(doubleClicked(QModelIndex)), parent, SLOT(slotCarilerEdit(const QModelIndex)));

    void slotCarilerEdit(const QModelIndex qm)
    {

    formCari *ce = new formCari(this, qm.sibling(qm.row(),0).data().toString());
    ce->exec();
    return;

    }

    Now we would like to do something else with this table. We would like to select something from the the table and send it to slotCarilerEdit with a push button. Any suggestion that we could use?

  13. #12
    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: QT Table Model

    Quote Originally Posted by aekilic View Post
    We would like to select something from the the table and send it to slotCarilerEdit with a push button. Any suggestion that we could use?
    In Qt, how do you act in general to a button click? The answer is; signals and slots.
    J-P Nurmi

Similar Threads

  1. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 20:17
  2. Relational Table Model Problem
    By aekilic in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2007, 14:57
  3. displaying any table on a qdatatable
    By Philip_Anselmo in forum Newbie
    Replies: 4
    Last Post: 9th May 2006, 22:12
  4. creating table plugin
    By mgurbuz in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:50
  5. Table model / view editing issue
    By Caius Aérobus in forum Qt Programming
    Replies: 9
    Last Post: 7th April 2006, 11:03

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.