Kubuntu 22.04 - Open File Dialog - Can we have access to the controls?
-
I am on Kubuntu 22.04.
I use QFileDialog to create an Open File dialog box.
There are EDITBOXes, COMBO BOXes, BUTTONs on the dialog box.
Can we have access to those controls and maybe disable them or change their properties?For example, I would like make the file filter a non editable COMBOBOX. In other words, I don’t want the user to be able to type in it as if it was a EDITBOX.
I want it to be just a COMBOBOX. The user can only drop the list and select something.fileFilter="Text files - *.txt (*.txt)"; selectedFilter="Text files - *.txt (*.txt)"; aDlg=new QFileDialog(this, "Open Text File", pFolderPath_WordsFile, fileFilter); aDlg->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Files); aDlg->selectNameFilter(selectedFilter); aDlg->setFileMode(QFileDialog::ExistingFile); aDlg->setOption(QFileDialog::DontUseNativeDialog, true); aDlg->exec();
Also, is there is Linux specific subforum?
-
I am on Kubuntu 22.04.
I use QFileDialog to create an Open File dialog box.
There are EDITBOXes, COMBO BOXes, BUTTONs on the dialog box.
Can we have access to those controls and maybe disable them or change their properties?For example, I would like make the file filter a non editable COMBOBOX. In other words, I don’t want the user to be able to type in it as if it was a EDITBOX.
I want it to be just a COMBOBOX. The user can only drop the list and select something.fileFilter="Text files - *.txt (*.txt)"; selectedFilter="Text files - *.txt (*.txt)"; aDlg=new QFileDialog(this, "Open Text File", pFolderPath_WordsFile, fileFilter); aDlg->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Files); aDlg->selectNameFilter(selectedFilter); aDlg->setFileMode(QFileDialog::ExistingFile); aDlg->setOption(QFileDialog::DontUseNativeDialog, true); aDlg->exec();
Also, is there is Linux specific subforum?
@stretchthebits
Did you tryQObject::findChildren<>()
to see if you can access widgets? -
I tried this. It compiles and runs fine but it has no effect on the COMBOX.
QList<QComboBox *> allComboBoxes=aDlg->findChildren<QComboBox *>(); for(i=0; i<allComboBoxes.size(); i++) { allComboBoxes[i]->setEditable(false); }
-
I tried this. It compiles and runs fine but it has no effect on the COMBOX.
QList<QComboBox *> allComboBoxes=aDlg->findChildren<QComboBox *>(); for(i=0; i<allComboBoxes.size(); i++) { allComboBoxes[i]->setEditable(false); }
@stretchthebits
If they don't expose whatever they are using, and if they are not found asQWidget
s (try doing aaDlg->findChildren<QWidget *>()
to see everything they have there), then I don't know how you access stuff on this dialog. You could look at the source code..... -
I tried this. It compiles and runs fine but it has no effect on the COMBOX.
QList<QComboBox *> allComboBoxes=aDlg->findChildren<QComboBox *>(); for(i=0; i<allComboBoxes.size(); i++) { allComboBoxes[i]->setEditable(false); }
@stretchthebits
Test with Kubuntu 21.04 Qt 5.12.11QString fileFilter="Text files - *.txt (*.txt)"; QString selectedFilter="Text files - *.txt (*.txt)"; auto aDlg=new QFileDialog(nullptr, "Open Text File", "", fileFilter); aDlg->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Files); aDlg->selectNameFilter(selectedFilter); aDlg->setFileMode(QFileDialog::ExistingFile); aDlg->setOption(QFileDialog::DontUseNativeDialog, true); for(int i=0; i<aDlg->layout()->count(); i++) { QLayoutItem *item=aDlg->layout()->itemAt(i); qDebug()<<item->widget(); } /* QLabel(0x5577e38ca3c0, name="lookInLabel") QWidget(0x0) QSplitter(0x5577e38cd160, name="splitter") QLabel(0x5577e38d9d30, name="fileNameLabel") QLineEdit(0x5577e38da130, name="fileNameEdit") QDialogButtonBox(0x5577e39e2390, name="buttonBox") QLabel(0x5577e39e4630, name="fileTypeLabel") QComboBox(0x5577e398c620, name="fileTypeCombo") */ QList<QComboBox*> allComboBoxes=aDlg->findChildren<QComboBox*>("fileTypeCombo"); if(allComboBoxes.count()) { QComboBox *combo=allComboBoxes.at(0); combo->setEditable(false); // combo->setEditable(true); // now editable (not editable by default for me) qDebug()<<combo; }
-
@stretchthebits
If they don't expose whatever they are using, and if they are not found asQWidget
s (try doing aaDlg->findChildren<QWidget *>()
to see everything they have there), then I don't know how you access stuff on this dialog. You could look at the source code.....@JonB
QList<QComboBox *> allComboBoxes=aDlg->findChildren<QComboBox *>();
does return 2 COMBOBOXes.
The first is called
lookInCombo.
I think this is the COMBOBOX for choosing your folder.The second is called
fileTypeCombo
I think this is the COMBOBOX for choosing your file filter.We can see this in what mpergand posted.
Also, what is the difference between
aDlg->setOption(QFileDialog::DontUseNativeDialog, true);
and
aDlg->setOption(QFileDialog::DontUseNativeDialog, false);In both cases, the dialog box looks nearly identical (but not exactly) except that when “true”, the file filter COMBOBOX is not editable.
I tried mpergand’s code. Yes, there is a single COMBOBOX called
fileTypeCombobut it still seems not possible to set it as non-editable.
The only solution seems to be to call the magical function:
aDlg->setOption(QFileDialog::DontUseNativeDialog, true); -
@JonB
QList<QComboBox *> allComboBoxes=aDlg->findChildren<QComboBox *>();
does return 2 COMBOBOXes.
The first is called
lookInCombo.
I think this is the COMBOBOX for choosing your folder.The second is called
fileTypeCombo
I think this is the COMBOBOX for choosing your file filter.We can see this in what mpergand posted.
Also, what is the difference between
aDlg->setOption(QFileDialog::DontUseNativeDialog, true);
and
aDlg->setOption(QFileDialog::DontUseNativeDialog, false);In both cases, the dialog box looks nearly identical (but not exactly) except that when “true”, the file filter COMBOBOX is not editable.
I tried mpergand’s code. Yes, there is a single COMBOBOX called
fileTypeCombobut it still seems not possible to set it as non-editable.
The only solution seems to be to call the magical function:
aDlg->setOption(QFileDialog::DontUseNativeDialog, true);@stretchthebits said in Kubuntu 22.04 - Open File Dialog - Can we have access to the controls?:
Also, what is the difference between
aDlg->setOption(QFileDialog::DontUseNativeDialog, true);
and
aDlg->setOption(QFileDialog::DontUseNativeDialog, false);The first uses a Qt file chooser dialog, the second whatever "native" one is available, see the docs. They may or may not be similar. On the native one you can only do whatever it allows, e.g. maybe it has a combobox but ignores non-editable and only the Qt one does allow that.