Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-50871

QFileDialog: wrong singleclick style hint query?

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.6.1
    • 5.5.1
    • GUI: Look'n'Feel
    • None
    • 5795c86e8b84d9026c2c768e816d2aea620a7ec7

    Description

      While investigating a problem with double/signle click open I have relized this commit is not 100% valid.

      There is a query for the style hint without particular object which can lead to wrong value in case there is a style sheet with "activate-on-singleclick" attached.

      Scenario: on system with standard double click file selection we want to have an app in which single click is used => we create an application with specific style sheet "QAbstractItemView { activate-on-singleclick: 1; }". In file dialog which can select multiple files the dialog is submitted even if the modifying CTRL key is used with click.

      main.cpp
      #include <QApplication>
      #include <QFileDialog>
      
      int main(int argc, char * argv[])
      {   
          QApplication app{argc, argv};
          app.setStyleSheet(QStringLiteral("QAbstractItemView { activate-on-singleclick: 1; }"));
          QFileDialog *d = new QFileDialog(nullptr
                  , QStringLiteral("Choose file")
                  , QStringLiteral(".")
                  , QStringLiteral("everything (*.*)"));
          d->setAttribute(Qt::WA_DeleteOnClose);
          d->setOption(QFileDialog::DontUseNativeDialog);
          d->setFileMode(QFileDialog::ExistingFiles);
          d->show();
      
          return app.exec();
      }
      

      I think the style hint should be queried like this:

      diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp
      index a9d5574..4f49cc2 100644
      --- a/src/widgets/dialogs/qfiledialog.cpp
      +++ b/src/widgets/dialogs/qfiledialog.cpp
      @@ -3547,7 +3547,7 @@ void QFileDialogPrivate::_q_enterDirectory(const QModelIndex &index)
               }
           } else {
               // Do not accept when shift-clicking to multi-select a file in environments with single-click-activation (KDE)
      -        if (!q->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)
      +        if (!q->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, &qFileDialogUi->treeView->viewOptions(), qFileDialogUi->treeView)
                   || q->fileMode() != QFileDialog::ExistingFiles || !(QGuiApplication::keyboardModifiers() & Qt::CTRL)) {
                   q->accept();
               }
      

      (the _q_enterDirectory() is called also if activated() by the qFileDialogUi->listView, but in that case the else should never reach)

      Of course I could miss something.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            palinek Palo Kisa
            palinek Palo Kisa
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes