| Trolltech Home | Qt4-preview-feedback Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 1 | |
see the attached program code... short description of the program: I use 2 views, each one has its own model. The views are attached each to one tab of a QTabWidget and the selection models' currentRowChanged() signal is connected to Test class objects whose only purpose it is to output the signals parameters and the associated model index. problem: Now when I start the program and just switch between the tabs without selecting anything, no currentRowChanged() signal is emitted which is correct, but when I select one item in one of the views and switch to the other tab, the other QSelectionModel emits a currentRowChanged() signal as well with the first item of the model being selected although no item was selected there -> this shouldn't happen, should it? The other selection should not change if the first one has.
#include "Test.h"
#include "Test.h"
#include <QApplication>
#include <QString>
#include <QtGui>
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
QWidget* main = new QWidget();
QStringList items;
items << "1" << "2" << "3" << "4";
QStringListModel* model1 = new QStringListModel( items, main );
QStringListModel* model2 = new QStringListModel( items, main );
QTableView* view1 = new QTableView();
QTableView* view2 = new QTableView();
view1->setModel( model1 );
view2->setModel( model2 );
QTabWidget* tab = new QTabWidget( main );
tab->addTab( view1, "view1" );
tab->addTab( view2, "view2" );
QVBoxLayout* layout = new QVBoxLayout( main );
layout->addWidget( tab );
// layout->addWidget( view2 );
Test* test1 = new Test("model1");
Test* test2 = new Test("model2");
QObject::connect( view1->selectionModel(), SIGNAL( currentRowChanged( const QModelIndex&, const QModelIndex& ) ), test1, SLOT( currentRowChanged(const QModelIndex&, const QModelIndex&) ) );
QObject::connect( view2->selectionModel(), SIGNAL( currentRowChanged( const QModelIndex&, const QModelIndex& ) ), test2, SLOT( currentRowChanged(const QModelIndex&, const QModelIndex&) ) );
main->show();
return app.exec();
}
TEMPLATE = app
TEMPLATE = app SOURCES += test.cpp CONFIG += qt \ warn_on QT += core \ gui \ svg HEADERS += Test.h
#ifndef TEST_H
#ifndef TEST_H
#define TEST_H
#include <QObject>
#include <QModelIndex>
#include <QtDebug>
class Test : public QObject {
Q_OBJECT
public:
Test( const QString& name ) : QObject(), m_name(name) {}
QString m_name;
public slots:
void currentRowChanged( const QModelIndex& newIndex, const QModelIndex& oldIndex) {
qDebug() << m_name;
qDebug() << newIndex;
qDebug() << oldIndex;
}
};
#endif
Attachment:
Attachment:
signature.asc
Attachment:
Attachment:
signature.asc
Description: This is a digitally signed message part.
Message 2 in thread
ok, just saw what's actually happening:
when I select an item of the view it gets the focus instead of the tab of the
TabWidget and when I change tabs then not the new one gets focus but the
other view and that's causing the change
so, my mistake, sorry
On Sunday 13. May 2007, Nico Kruber wrote:
> see the attached program code...
>
> short description of the program: I use 2 views, each one has its own
> model. The views are attached each to one tab of a QTabWidget and the
> selection models' currentRowChanged() signal is connected to Test class
> objects whose only purpose it is to output the signals parameters and the
> associated model index.
>
> problem: Now when I start the program and just switch between the tabs
> without selecting anything, no currentRowChanged() signal is emitted which
> is correct, but when I select one item in one of the views and switch to
> the other tab, the other QSelectionModel emits a currentRowChanged() signal
> as well with the first item of the model being selected although no item
> was selected there
> -> this shouldn't happen, should it? The other selection should not change
> if the first one has.
Description: This is a digitally signed message part.