Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Create open multiselect dialog to only directories
Forum Updated to NodeBB v4.3 + New Features

Create open multiselect dialog to only directories

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pmendozav
    wrote on last edited by
    #1

    I found this code:
    @
    QFileDialog* _f_dlg = new QFileDialog(this);
    _f_dlg->setFileMode(QFileDialog::DirectoryOnly);
    _f_dlg->setOption(QFileDialog::DontUseNativeDialog, true);

    QListView *l = _f_dlg->findChild<QListView*>("listView");
    if (l)
    {
        l->setSelectionMode(QAbstractItemView::MultiSelection);
    }
    QTreeView *t = _f_dlg->findChild<QTreeView*>();
    if (t) {
        t->setSelectionMode(QAbstractItemView::MultiSelection);
    }
    
    int nMode = _f_dlg->exec&#40;&#41;;
    QStringList _fnames = _f_dlg->selectedFiles();
    

    @

    But, this code return the path of current directory. For example: in "C:", I go inside of "images" and inside I choose 3 directories (folder1, folder2, folder3). But the result is a vector of strings of 4 elements:

    • C:\images

    • C:\images\folder1

    • C:\images\folder2

    • C:\images\folder3

    I don't understand because. I want to remove that element (the path)

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Ouch, modifying the dialog like that. That's ugly and will break when they decide to change eg. "listview" to "someList".
      I would strongly suggest to implement your own dialog for that using eg. "QFileSystemModel":http://qt-project.org/doc/qt-5/qfilesystemmodel.html

      If not then as you're "doing it wrong" already you might just as well modify the returned list the way you wanted:
      @
      _fnames.removeFirst();
      std::for_each(_fnames.begin(), _fnames.end(), [](QString& s){ s = QDir(s).dirName(); });
      @

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved