QFileDialogAppearance on Linux

Discuss anything related to product development
Post Reply
seasoned_geek
Posts: 61
Joined: Thu Jun 11 2020 12:18 pm

QFileDialogAppearance on Linux

Post by seasoned_geek »

all,

I tested this out on Fedora (current) and Ubuntu 20.04. This is what QFileDailog looks like.
https://www.logikalsolutions.com/wordpress/wp-content/uploads/2020/09/file-dialog-1.png

According to the doc it should be providing the "system file dialog" (or wording something like that). On Ubuntu the system file dialog looks like this:
https://www.logikalsolutions.com/wordpress/wp-content/uploads/2020/09/file-dialog-2.png

It didn't matter if I set this option true/false, I always got the same dialog as the image in the first link. No ability to navigate to network drives or enable the viewing of hidden files.

https://www.logikalsolutions.com/wordpress/wp-content/uploads/2020/09/file-dialog-3.png

I created a Qt test app using whatever was on that Ubuntu 20.04 machine. The zip of which should download from this link
https://www.logikalsolutions.com/wordpress/wp-content/uploads/2020/09/TestFileDialog.zip

I didn't fully flesh this out, just got enough to launch each dialog.

Code: Select all

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QFileDialog>
#include <QStringList>
#include <QDir>
#include <QDebug>
#include <QProcess>
#include <QByteArray>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::fileDialogOpen);
    connect(ui->actionOpen_File, &QAction::triggered, this, &MainWindow::zenityOpen);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::fileDialogOpen()
{
    QStringList lst = QFileDialog::getOpenFileNames(this, "Choose file", QDir::homePath());

    qDebug() << "files: " << lst;
}

void MainWindow::zenityOpen()
{
    // yes I cheated hard coding the path
    QString cmd = QString("/usr/bin/zenity --file-selection --title=\"Select a File\" --multiple");

    QProcess *myProcess = new QProcess(this);

    qDebug() << "Zenity command: " << cmd;

    myProcess->start(cmd);
    myProcess->waitForFinished();
    QByteArray a = myProcess->readAllStandardOutput();

    qDebug() << "Zenity returned: " << a << "  ExitStatus: " << myProcess->exitStatus();

    myProcess->deleteLater();
}
QFileDialog using Qt 5.x default on Ubuntu 20.04
https://www.logikalsolutions.com/wordpress/wp-content/uploads/2020/09/file-qt5-ubuntu.png

Zenity on Ubuntu 20.04
https://www.logikalsolutions.com/wordpress/wp-content/uploads/2020/09/file-zenity-u20-qt5.png

Zenity test Qt 5
https://www.logikalsolutions.com/wordpress/wp-content/uploads/2020/09/file-other.png

Zenity navigate to other
https://www.logikalsolutions.com/wordpress/wp-content/uploads/2020/09/file-other.png

Choose SortPairs.cpp
https://www.logikalsolutions.com/wordpress/wp-content/uploads/2020/09/file-sortpairs.png

This came back
https://www.logikalsolutions.com/wordpress/wp-content/uploads/2020/09/file-selected.png

As one can see from the screenshots it looks like QFileDialog in Qt 5.x is using Zenity on Ubuntu default desktop. I didn't spin up a system with Qt 4.8 to see if I've just been working with Qt 5.x too long. I also didn't spin up a KDE system to see if they are using KDialog on it or if Zenity exists on most. Zenity does exist on my Fedora system, but it is Gnome based so that is not a shock.

Does QFileDialog have some outstanding issues on Linux in CopperSpice? [edited]

Thanks

Post Reply