QFileDialog not displaying well after loading proj

2019-05-30 05:48发布

问题:

I have a problem with QFileDialog in a software that my friend and I are developing.

The software is a CAD programmed in C++/Qt(5.6) , so it uses a lot the MVC design pattern. The problem is the following :

We use QFileDialog when we are about to load or save a project.

-When we start the software and we first load the project, everything works fine

-When we try to load again, the QFileDialog doesn't display well. It does not seem frozen, the only displayed part (folders part, on the left) responds but does not display any file on the center.

The only difference I see is that after the first load, QGraphicsItem are created and updated in order to display the parts of the loaded project. Do you know what could be the problem ?

EDIT - The Code

QFileDialog fileDialog(0,tr("Load Project"), "./..", tr("CAD files (*.json)"));
fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
fileDialog.setFileMode(QFileDialog::ExistingFiles);
if (QDialog::Accepted != fileDialog.exec())
    return NULL;

QStringList sel = fileDialog.selectedFiles();

EDIT 2 - A working solution By forcing Qt not to use the native dialog we can display a window correctly.

fileDialog.setOption(QFileDialog::DontUseNativeDialog,true);

We are on Linux Mint 17.2, with cinnamon. Did you know any conflict between Qt and Cinnamon ?

回答1:

It might be a problem with the relative directory/path "./..". Try replacing it with something else, for example QDir::home().absolutePath()

QFileDialog fileDialog(0,
                       tr("Load Project"), 
                       QDir::home().absolutePath(), 
                       tr("CAD files (*.json)"));

Qt might also conflicting with something that is installed on the machine, as noted by @ElevenJune:

By forcing Qt not to use the native dialog we can display a window correctly.

That sounds like a conflict to me... Are you using any other libraries than Qt within the app?