0
votes

I have changed my QTreeWidget to allow extended selection:

tree_->setSelectionMode(QAbstractItemView::ExtendedSelection);

There is a case in which the selectionChanged signal is not emitted. This is when I directly select multiple items with the mouse. If I first click on an item and then keep shift and select a range, then the selectionChanged signal is emitted.

Has anybody seen this?

1

1 Answers

0
votes

Which operating system/Qt version are you using? I've seen strange bugs like this on one OS that will disappear on another (I haven't seen this one, though).

I'm using Qt 4.8.2 under Linux, and I don't think I'm seeing this behaviour. Here's the code I've got:

MyWindow.h:

#include <QMainWindow>
#include <QWidget>

class MyWindow : public QMainWindow
{
  Q_OBJECT
public:
  MyWindow(QWidget * = 0, Qt::WindowFlags = 0 );

private slots:
  void printSelectionChanged();

};

MyWindow.cpp:

#include "MyWindow.h"

#include <QAbstractItemView>
#include <QList>
#include <QString>
#include <QStringList>
#include <QTreeWidget>
#include <QTreeWidgetItem>

#include <iostream>
using namespace std;

MyWindow::MyWindow(QWidget *parent, Qt::WindowFlags flags)
 : QMainWindow(parent, flags)
{
  QTreeWidget *treeWidget = new QTreeWidget(this);
  treeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
  treeWidget->setColumnCount(1);
  QList<QTreeWidgetItem *> items;

  for (int i = 0; i < 10; ++i)
    items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i))));
  treeWidget->insertTopLevelItems(0, items);

  connect(treeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(printSelectionChanged()));

  setCentralWidget(treeWidget);

}

void MyWindow::printSelectionChanged()
{
  cout << "selection has changed." << endl;
}

Maybe you should post your code (or some simplified version thereof), if you're doing something differently.