Results 1 to 13 of 13

Thread: QTableView selection problem

  1. #1
    Join Date
    Aug 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTableView selection problem

    Hi,

    I am developing a program using QTableView. I am sort of lazy using QStandardItemModel
    to create the default empty table. The data inputed to the model is dynamic.

    itemmodel_=new QStandardItemModel(0,5);
    itemmodel_->setHeaderData(0, Qt::Horizontal, tr("View"));
    itemmodel_->setHeaderData(1, Qt::Horizontal, tr("Gene type"));
    itemmodel_->setHeaderData(2, Qt::Horizontal, tr("Proportion (%)"));
    itemmodel_->setHeaderData(3, Qt::Horizontal, tr("Time (msec)"));
    itemmodel_->setHeaderData(4, Qt::Horizontal, tr("Density"));

    QItemSelectionModel* selmodel = ODTableView->selectionModel();
    ODTableView->setSelectionMode(QAbstractItemView::ExtendedSelec tion);
    QObject::connect(selmodel, SIGNAL(selectionChanged(const QItemSelection &,
    const QItemSelection &)),
    this, SLOT(slectionHandle(const QItemSelection &,
    const QItemSelection &)) );

    In my application I want to select "rows" or "all" to generate a signal to update statistical
    graph in another dialog. But now the selectionChanged signal is not released when the
    mouse changes selection in the table view. Actually, I tried to connect the signal even after
    the table items are added but still not work. additionally, the table view is set to visible only if data are loaded. Can anyone help?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView selection problem

    What about the currentChanged signal?

  3. #3
    Join Date
    Aug 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView selection problem

    Hi,
    Thanks for reply! I thought no one would help.
    actually I tried currentChanged signal. it is not working either. currently, I had a solution
    using an eventfiler on the table view. However, I just want to know how to solve this
    problem.
    /AI

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView selection problem

    But this is not normal...
    Can you post a small program that reproduces this bug?

    What about the QAbstractItemViere::clicked(const QModelIndex&) signal?
    At least one should get emitted when you select something.

    Regards

  5. #5
    Join Date
    Aug 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView selection problem

    Hi,
    yeah, it is a bit weird for me as well. Probably something silly I did .
    But I tried clicked() signal in QTableView it works. I will try some simple
    program since the application is not simple to show.
    /AI

  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: QTableView selection problem

    Could it be a missing Q_OBJECT macro? Does QObject::connect() output any warning?
    J-P Nurmi

  7. #7
    Join Date
    Aug 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Angry Re: QTableView selection problem

    Hi,

    I test abit and find that the real problem is that selection handling crashes when getting
    selectionChanged() signal:

    void ODCheckerDlg::selectionHandle( const QItemSelection& sel,
    const QItemSelection& unsel)
    {
    ....

    const QList<QModelIndex>& indlist=sel.indexes();

    .....

    }

    this crash appears in windows with QT4.2.

    /AI

  8. #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: QTableView selection problem

    Could you prepare a minimal compilable example reproducing the problem, please?
    J-P Nurmi

  9. #9
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTableView selection problem

    But according to 4.4.0 docs, selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) is a SLOT, not a SIGNAL. This logic is not understandable by me. Why is slot, it should be signal?! And how do I know according to parameters of this slot, what is the index of selected item in table?!
    Qt 5.3 Opensource & Creator 3.1.2

  10. #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: QTableView selection problem

    Quote Originally Posted by MarkoSan View Post
    But according to 4.4.0 docs, selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) is a SLOT, not a SIGNAL. This logic is not understandable by me. Why is slot, it should be signal?! And how do I know according to parameters of this slot, what is the index of selected item in table?!
    I guess you're talking about QAbstractItemView::selectionChanged() which is provided for convenience. But actually there is QItemSelectionModel::selectionChanged() which is a signal.
    J-P Nurmi

  11. #11
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTableView selection problem

    Quote Originally Posted by jpn View Post
    I guess you're talking about QAbstractItemView::selectionChanged() which is provided for convenience. But actually there is QItemSelectionModel::selectionChanged() which is a signal.
    So, in object, subclassed from QTableView, which one is now called?!
    Qt 5.3 Opensource & Creator 3.1.2

  12. #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: QTableView selection problem

    Quote Originally Posted by MarkoSan View Post
    So, in object, subclassed from QTableView, which one is now called?!
    The documentation is quite clear about that.

    QItemSelectionModel::selectionChanged():
    This signal is emitted whenever the selection changes.
    QAbstractItemView::selectionChanged():
    This slot is called when the selection is changed.
    QAbstractItemView establishes the signal slot connection between the two.
    J-P Nurmi

  13. #13
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTableView selection problem

    Quote Originally Posted by jpn View Post
    The documentation is quite clear about that.

    QItemSelectionModel::selectionChanged():

    QAbstractItemView::selectionChanged():

    QAbstractItemView establishes the signal slot connection between the two.
    Ok, but, actually, documentation IS NOT QUITE CLEAR ABOUT THAT. That is my point.

    So, if that is the way, I have a problem: I have a subclassed QWidget and in it there is a subclassed QTableView and QPushButton. This QPushButton is initialy disabled (because QTableView is empty at runtime). The purpose of this QPushButton is to remove item from QTableView (when pressed), so if QTableView is NOT empty and NONE of items is selected, it must be disabled. So, I need to catch signal on selection change and enable this button. The problem is, that QTableView and QPushButton are not aware of each other and I must do it through parent QWidget. So, should I catch signal selectionChanged or SLOT selectionChanged?!
    Last edited by MarkoSan; 9th June 2008 at 13:17.
    Qt 5.3 Opensource & Creator 3.1.2

Similar Threads

  1. QTableView multiline problem
    By ramazangirgin in forum Qt Programming
    Replies: 3
    Last Post: 3rd August 2007, 10:02
  2. QTableView refresh problem
    By tebessum in forum Qt Programming
    Replies: 3
    Last Post: 29th December 2006, 11:22
  3. Qtreeview selection highlighted problem?
    By thefisher in forum Qt Programming
    Replies: 4
    Last Post: 24th November 2006, 09:50
  4. Selection problem in QTreeView
    By Valheru in forum Qt Programming
    Replies: 3
    Last Post: 7th October 2006, 16:02
  5. CheckBox and selection in QTableView
    By Mike Krus in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2006, 20:31

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.