Change QFileDialog :: getOpenFileName to add

I am a student programmer using Qt to create a reading table for my company. This reader is both an editor and a converter. It reads in a .i file, allows editing a text document, and then produces a .scf file, which is essentially a split values ​​file laid out under a legend built with headers. I'm distracted ... Basically, the imported file format is very difficult to scan and read (mostly impossible), so I would like to modify the open preBuilt QFileDialog file to include an additional snapshot when older file types are selected to declare their template headers.

When the user selects the .i extension files (file type of option 2), I would like to include an additional drop-down menu so that the user can choose which type of .i file he (selected template). This way, I don’t have to deal with God, knows how many hours trying to figure out a way to index all the headers into a table for every other type. Currently, my importFile function is invoking a dialog using this:

QString fileLocation = QFileDialog::getOpenFileName(this,("Open File"), "", ("Simulation Configuration File(*.scf);;Input Files(*.prp *.sze *.i *.I *.tab *.inp *.tbl)")); //launches File Selector 

I was referring to the QFileDialog Documentation to try and find the solution that I needed, but didn't help. Thank you for reading my post and in advance for some direction that you can give about this.

UPDATE MAR 16 2012; First, I would like to thank Masks for his initial support in this matter. Below is the communication operator that I receive with the error I received.

 //Declared data type QFileDialog openFile; QComboBox comboBoxTemplateSelector; connect(openFile, SIGNAL(currentChanged(const &QString)), this, SLOT(checkTemplateSelected())); openFile.layout()->addWidget(comboBoxTemplateSelector); 

compile errors

I also noticed that I didn’t like the way I added the QComboBox to the modified dialog layout (which is the second error). I really hope that I'm just doing something dumb here and its easy task to overcome.

In response to a comment by tmpearce heres my header code;

 #include <QWidget> namespace Ui { class ReaderTable; } class ReaderTable : public QWidget { Q_OBJECT public: explicit ReaderTable(QWidget *parent = 0); ~ReaderTable(); public slots: void checkTemplateSelected(); void importFile(); void saveFile(); private: Ui::ReaderTable *ui; }; 

Thank you for reading and in advance for any contributions to this task!

+6
source share
2 answers

A QFileDialog instance (do not call the static getOpenFileName method), refer to its layout and add a disabled QComboBox to it.

 // mydialog_ and cb_ could be private fields inside MyClass mydialog_ = new QFileDialog; cb_ = new QComboBox; cb_->setEnabled(false); connect(mydialog, SIGNAL(currentChanged(const QString&)), this, SLOT(checkFilter(const QString&))); mydialog_->layout()->addWidget(cb_); if (mydialog_->exec() == QDialog::Accepted) { QString selectedFile = mydialog_->selectedFiles()[0]; QString cbSelection = cb_->currentText(); } 

the slot will be something like this:

 void MyClass::checkFilter(const QString& filter) { cb_->setEnabled(filter == "what_you_want"); } 

returning from the exec () dialog, you can get the selected file and the current cb_ selection. Note that you can add something more complex than a simple QComboBox at the bottom of the dialog, taking care of gui cosmetics.

Actually, I don't really like this approach (but that was what you asked for :-). I would do a simple dialog like this:

enter image description here

and enable combos only if the selected file meets your criteria. The browse button can invoke the static getOpenFileMethod method in QFileDialog.

+6
source

You can process the selection of an element by this signal:
void QFileDialog::fileSelected ( const QString & file )
Then this will happen, call setFilter with the type you want.
Sorry if I do not understand your task.

0
source

Source: https://habr.com/ru/post/910734/


All Articles