From f9408317e70bc2e635a2f9baeff35d1c06227734 Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Thu, 23 Oct 2014 10:30:39 +0200 Subject: Auto-scroll while selecting entire rows/columns did not work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you press and hold a section in a header view you can extend the selection to more rows by moving the mouse. This worked fine until you moved the mouse outside the geometry of the header view. The expected behavior was then to scroll the view (this is what happens with extended selections on regular table cells). [ChangeLog][QtWidgets][QHeaderView] Auto-scroll the view when making extended row/column selections. Change-Id: Ic65aa34d370e74054b2123ab57edb1add0e8adb9 Task-number: QTBUG-21201 Reviewed-by: Thorbjørn Lund Martsum --- .../itemviews/qheaderview/qheaderviewtest1.cpp | 163 +++++++++++++++++++-- 1 file changed, 152 insertions(+), 11 deletions(-) (limited to 'tests/manual/widgets/itemviews/qheaderview/qheaderviewtest1.cpp') diff --git a/tests/manual/widgets/itemviews/qheaderview/qheaderviewtest1.cpp b/tests/manual/widgets/itemviews/qheaderview/qheaderviewtest1.cpp index cfe24a25da..e01e2cec5e 100644 --- a/tests/manual/widgets/itemviews/qheaderview/qheaderviewtest1.cpp +++ b/tests/manual/widgets/itemviews/qheaderview/qheaderviewtest1.cpp @@ -33,6 +33,148 @@ #include +struct ManualTask { + const char *title; + const char *instructions; + unsigned sectionsMovable : 1; + unsigned selectionMode : 3; +}; + +ManualTask tasks[] = { +{ QT_TR_NOOP("0. Default"), + "Please provide instructions", + true, QAbstractItemView::SingleSelection +}, +{ QT_TR_NOOP("1. Autoscroll"), + "
    " + "
  1. Press and hold on section 9 of vertical header.
    " + "(all cells in the row will be selected)" + "
  2. " + "
  3. Extend the selection by moving the mouse down.
    " + "(selection will extend to the next rows)" + "
  4. " + "
  5. Continue to move the mouse down and outside the window geometry.
    " + "(The view should scroll automatically and the selection should still extend)" + "
  6. " + "
  7. While still holding the button, do the same in the opposite direction, i.e. move mouse up and outside the window geometry.
    " + "(Verify that the view scrolls automatically and the selection changes)" + "
  8. " + "
  9. Verify that it works in the other dimension, i.e Press and hold section 9 of the horizontal header.
    " + "All cells in the column will be selected" + "
  10. " + "
  11. Extend the selection by moving the mouse to the far right and outside the window geometry.
    " + "(selection will extend to the next columns)" + "
  12. " + "
  13. Verify that it works in the opposite direction (i.e. move mouse to the left of the window geometry).
    " + "(Verify that the view scrolls automatically and the selection changes)" + "
  14. " + "
", + false, QAbstractItemView::ExtendedSelection +} + +}; + + +class Window : public QWidget +{ + Q_OBJECT +public: + Window(QWidget *parent = 0): QWidget(parent), ckMovable(0), tableView(0), cbSelectionMode(0), m_taskInstructions(0) + { + m_taskInstructions = new QLabel(); + if (sizeof(tasks) > 0) + m_taskInstructions->setText(tr(tasks[0].instructions)); + + QVBoxLayout *vbox = new QVBoxLayout(this); + vbox->addLayout(setupComboBox()); + vbox->addWidget(setupGroupBox()); + vbox->addWidget(setupTableView()); + vbox->addWidget(m_taskInstructions); + } + + void updateControls() + { + ckMovable->setChecked(tableView->verticalHeader()->sectionsMovable()); + QAbstractItemView::SelectionMode sMode = tableView->selectionMode(); + cbSelectionMode->setCurrentIndex((int)sMode); + } + +private: + QFormLayout *setupComboBox() + { + QComboBox *combo = new QComboBox; + for (size_t i = 0; i < sizeof(tasks) / sizeof(tasks[0]); ++i) { + combo->addItem(tr(tasks[i].title)); + } + + connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_taskCombo_currentIndexChanged(int))); + QFormLayout *form = new QFormLayout; + form->addRow(tr("Choose task:"), combo); + return form; + } + + QGroupBox *setupGroupBox() + { + QGroupBox *grp = new QGroupBox(tr("Properties")); + QFormLayout *form = new QFormLayout; + grp->setLayout(form); + ckMovable = new QCheckBox; + ckMovable->setObjectName(QLatin1String("ckMovable")); + connect(ckMovable, SIGNAL(toggled(bool)), this, SLOT(on_ckMovable_toggled(bool))); + form->addRow(tr("SectionsMovable"), ckMovable); + + cbSelectionMode = new QComboBox; + cbSelectionMode->setObjectName(QLatin1String("cbSelectionMode")); + cbSelectionMode->addItems(QStringList() << QLatin1String("NoSelection") + << QLatin1String("SingleSelection") + << QLatin1String("MultiSelection") + << QLatin1String("ExtendedSelection") + << QLatin1String("ContiguousSelection") + ); + + connect(cbSelectionMode, SIGNAL(currentIndexChanged(int)), this, SLOT(on_cbSelectionMode_currentIndexChanged(int))); + form->addRow(tr("SelectionMode"), cbSelectionMode); + return grp; + } + + QTableView *setupTableView() + { + tableView = new QTableView; + m.setRowCount(500); + m.setColumnCount(250); + tableView->setSelectionMode(QAbstractItemView::SingleSelection); + tableView->setModel(&m); + return tableView; + } + +private Q_SLOTS: + void on_ckMovable_toggled(bool arg) + { + tableView->verticalHeader()->setSectionsMovable(arg); + tableView->horizontalHeader()->setSectionsMovable(arg); + } + + void on_cbSelectionMode_currentIndexChanged(int idx) + { + tableView->setSelectionMode((QAbstractItemView::SelectionMode)idx); + } + + void on_taskCombo_currentIndexChanged(int idx) + { + ManualTask &task = tasks[idx]; + m_taskInstructions->setText(tr(task.instructions)); + ckMovable->setChecked(task.sectionsMovable); + cbSelectionMode->setCurrentIndex((QAbstractItemView::SelectionMode)task.selectionMode); + } + +public: + QCheckBox *ckMovable; + QTableView *tableView; + QStandardItemModel m; + QComboBox *cbSelectionMode; + QLabel *m_taskInstructions; +}; + class SomeHandler : public QObject { Q_OBJECT @@ -86,19 +228,18 @@ void SomeHandler::slotSectionResized(int logsection, int oldsize, int newsize) int main(int argc, char *argv[]) { QApplication app(argc, argv); - QTableView tv; - QStandardItemModel m; - m.setRowCount(500); - m.setColumnCount(250); - tv.setModel(&m); - tv.setSelectionMode(QAbstractItemView::SingleSelection); + Window window; // Comment in the line below to test selection with keyboard (space) // tv.setEditTriggers(QAbstractItemView::NoEditTriggers); - SomeHandler handler(tv.horizontalHeader(), &tv); - tv.horizontalHeader()->setDefaultSectionSize(30); - tv.show(); - tv.horizontalHeader()->setSectionsMovable(true); - tv.verticalHeader()->setSectionsMovable(true); + QHeaderView *hHeader = window.tableView->horizontalHeader(); + QHeaderView *vHeader = window.tableView->verticalHeader(); + SomeHandler handler(hHeader, window.tableView); + hHeader->setDefaultSectionSize(30); + window.resize(600, 600); + window.show(); + hHeader->setSectionsMovable(true); + vHeader->setSectionsMovable(true); + window.updateControls(); app.exec(); } #include "qheaderviewtest1.moc" -- cgit v1.2.3