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. [SOLVED]Registering fields from a QTreeView embedded in a QWizardPage
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Registering fields from a QTreeView embedded in a QWizardPage

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.6k 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.
  • C Offline
    C Offline
    cobaltsixty
    wrote on last edited by
    #1

    Hi all,

    I'm trying to build a wizard. As a very first step, I need a directory selection from user. I decided to use a QTreeView to make it happen. The problem for me is registering a field that contains user selection. I need help to understand how to this since I did not manage to use the registerField() function in such a context.

    Here is the code I use:
    @directoryPage::directoryPage(QWidget *parent) :
    QWizardPage(parent)
    {
    setTitle(tr("Selecting a directory"));

    QFileSystemModel *model = new QFileSystemModel();
    model->setFilter(QDir::Dirs);
    model->setRootPath(QDir::homePath());
    
    treeView = new QTreeView();
    treeView -> setModel(model);
    treeView -> setRootIndex(model->index(QDir::homePath()));
    treeView -> hideColumn(3);
    treeView -> hideColumn(2);
    treeView -> hideColumn(1);
    treeView -> setSelectionMode(QAbstractItemView::SingleSelection);
    
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(treeView);
    setLayout(layout);
    
    //registerField("inputDirectory", treeView, model->filePath(treeView->selectionModel()->selectedIndexes()));
    

    }
    @

    Thanks a lot for your help :-)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      QTreeView doesn't have such a property to register with QWizardPage. However you could subclass QTreeView and add the property yourself.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cobaltsixty
        wrote on last edited by
        #3

        [quote author="SGaist" date="1408304832"]Hi and welcome to devnet,

        QTreeView doesn't have such a property to register with QWizardPage. However you could subclass QTreeView and add the property yourself.

        Hope it helps[/quote]

        @SGaist, Thx. This could be a solution. I was just looking for something more straightforward. Will do if nothing else comes up. Cheers

        If I need to implement you solution, my first guess would be:

        • creating a class inheriting from QTreeView --> myQtreeView
        • adding a QString *selectedDirectory as a property
        • creating a private hasChanged() slot that "stores" the data
        • connecting this slot to the currentChanged signal from QItemSelectionModel (the model being retrieved from QTreeView::selectionModel().

        Sorry but I'm quite new to Qt. Do you think this is a correct strategy ?

        Thanks again.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cobaltsixty
          wrote on last edited by
          #4

          solved. Thanks.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Sorry I've lost track on this one. Nice you found out !

            Just one thing, no need to allocate QString on the heap

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            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