Qt customizing save file dialog

╄→гoц情女王★ 提交于 2020-01-02 04:47:06

问题


I need to customize default Qt save file dialog: add some options in it. For example, adding some checkboxes with my own values in it between file type and save/close buttons.

Have Qt any ways to do it?


回答1:


You can customize the Qt file dialog as long as you're okay with using the "non-native" Qt file dialog that comes with Qt; the other option Qt provides is to use the OS's native file dialog, but if you do that there is no way (that I'm aware of) to customize the dialog.

Here's an example of an enhanced file dialog class I wrote as part of an audio-format-conversion program. The code is a bit dated and may need a bit of tweaking to work with newer versions of Qt (in particular in Qt 4.6 and higher you'll probably need to call setOption(DontUseNativeDialog) on your file dialog object, otherwise you'll get the native dialog and custom widgets won't appear under MacOS/X), but the source code for it can be found in the source archive if you want to take a look.




回答2:


cfd.h

#include <QFileDialog>
#include <QPushButton>

class cfd : public QFileDialog
{
public:
    cfd();
};

cfd.cpp

#include "cfd.h"

cfd::cfd()
{
    ((QWidget*)this->children().at(3))->setFixedSize(200,200);
    (new QPushButton(this))->setFixedSize(300,30);
}

result



来源:https://stackoverflow.com/questions/7426603/qt-customizing-save-file-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!