<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QListView with file navigation]]></title><description><![CDATA[<p dir="auto">Hi! I am trying to implement a small file browser embedded in my application GUI with the QListView widget. I have successfully managed to display the contents of a predefined folder and filter only the XML type files I am interested in. However, I'd like to give users a choice of changing the root folder from within that list view. Is it possible to add folder navigation inside the widget? What would I need to add to my listview-&gt;doubleclicked slot?</p>
<p dir="auto">Here's my code:</p>
<pre><code>void MeasurementModePage::setupListView()
{
    QString protocolsPath = "D:/";
    qDebug() &lt;&lt; QCoreApplication::applicationFilePath();
    qDebug() &lt;&lt; QCoreApplication::applicationDirPath();
    qDebug() &lt;&lt; protocolsPath;
    listmodel = new QFileSystemModel(this);
    listmodel-&gt;setRootPath(protocolsPath);
    QStringList filters;
    filters &lt;&lt; "*.xml";
    listmodel-&gt;setFilter(QDir::NoDotAndDotDot | QDir::Files); // To be removed in case folders have to be also displayed
    listmodel-&gt;setNameFilters(filters);
    listmodel-&gt;setNameFilterDisables(false);
    listmodel-&gt;sort(0, Qt::AscendingOrder);
    ui-&gt;listView_measurementFiles-&gt;setModel(listmodel);
    ui-&gt;listView_measurementFiles-&gt;setRootIndex(listmodel-&gt;index(protocolsPath));
    connect(this, &amp;MeasurementModePage::settingsChanged, this, &amp;MeasurementModePage::onSettingsLoad);

    // Context menu
    ui-&gt;listView_measurementFiles-&gt;setContextMenuPolicy(Qt::CustomContextMenu);
    connect(ui-&gt;listView_measurementFiles, &amp;QWidget::customContextMenuRequested, this, &amp;MeasurementModePage:: showCustomContextMenu);
}

void MeasurementModePage::on_listView_measurementFiles_doubleClicked(const QModelIndex &amp;index)
{
    // Load an XML settings file if the index selected is a file
    if(listmodel-&gt;fileInfo(index).isFile())
    {
        // Load settings with external LIB
        emit settingsChanged();
    }
}
</code></pre>
<p dir="auto">On a side note: I would like the root path to be set to a folder where my application is built, where I will place some XML files for the users to choose from. Does it make sense to read it using "QCoreApplication::applicationDirPath();"?</p>
]]></description><link>https://forum.qt.io/topic/127655/qlistview-with-file-navigation</link><generator>RSS for Node</generator><lastBuildDate>Sun, 10 May 2026 13:26:25 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/127655.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 16 Jun 2021 14:08:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QListView with file navigation on Fri, 18 Jun 2021 07:47:23 GMT]]></title><description><![CDATA[<p dir="auto">I ended up implementing a QListView and added a tool button to allow users select any directory with a QFileDialog. Since I intend to make the program easy to use, I don't want them to change the root path frequently. I will place the XML files in a specific directory and the ability to change the folder displayed is just an additional functionality. Thanks for the suggestions!</p>
]]></description><link>https://forum.qt.io/post/666010</link><guid isPermaLink="true">https://forum.qt.io/post/666010</guid><dc:creator><![CDATA[szumial]]></dc:creator><pubDate>Fri, 18 Jun 2021 07:47:23 GMT</pubDate></item><item><title><![CDATA[Reply to QListView with file navigation on Thu, 17 Jun 2021 18:35:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/szumial">@<bdi>szumial</bdi></a> said in <a href="/post/665684">QListView with file navigation</a>:</p>
<blockquote>
<p dir="auto">Regarding the applitacion directory - the target platform is Windows and for now, the application will come without an installer - just a compiled version to work with.</p>
</blockquote>
<p dir="auto">Then you should be good.</p>
]]></description><link>https://forum.qt.io/post/665893</link><guid isPermaLink="true">https://forum.qt.io/post/665893</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 17 Jun 2021 18:35:56 GMT</pubDate></item><item><title><![CDATA[Reply to QListView with file navigation on Thu, 17 Jun 2021 06:34:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> I am thinking to give users a freedom of choice. The application would always launch showing the default root path, but they should be allowed to choose any other directory. I will only do the filtering and display XML files exclusively. I'll try with a tree view today and see if this achieves that goal.</p>
<p dir="auto">Regarding the applitacion directory - the target platform is Windows and for now, the application will come without an installer - just a compiled version to work with.</p>
]]></description><link>https://forum.qt.io/post/665684</link><guid isPermaLink="true">https://forum.qt.io/post/665684</guid><dc:creator><![CDATA[szumial]]></dc:creator><pubDate>Thu, 17 Jun 2021 06:34:13 GMT</pubDate></item><item><title><![CDATA[Reply to QListView with file navigation on Wed, 16 Jun 2021 16:53:41 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">It depends on the target platform and how you will install your application.</p>
<p dir="auto">How far would your users be allowed to roam for these xml files ?</p>
<p dir="auto">Depending on that, a tree view might be better suited.</p>
]]></description><link>https://forum.qt.io/post/665574</link><guid isPermaLink="true">https://forum.qt.io/post/665574</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 16 Jun 2021 16:53:41 GMT</pubDate></item></channel></rss>