[solved] directory tree and file list Beginners question
-
how do you use the setwindowmodality?
I need the browse window to be child and can not be reopened unless before closed@
Browse * w = new Browse(dB_Setting);
w->show;
@@ Browse class
this->setWindowModality(Qt::WindowModal);
@ -
Set it in your Browse class constructor:
@
Browser::Browser(QWidget *parent):QWidget(parent)
{
qDebug() << "input filename " << input_filename;
this->setWindowModality(Qt::ApplicationModal);
@If you really want to block event loop of main application and stay in on_loginbrowse_clicked function till user closes browse widget, make your Browse class subclass QDialog instead of QWidget, QDialog has own event loop. So your code will work well:
@
class Browse : public QDialog
{
Q_OBJECT
public:
...
@@
void Login::on_loginbrowse_clicked()
{
// selecting a new setting.dB file
Browse w("Setting.dB"); // Browse searching for Setting.dB
}@ -
I changed to QDialog as follows
@
class Browse : public QDialog
{
Q_OBJECTpublic:
explicit Browse(QString input_filename, QWidget *parent = 0);
~Browse();
QString OutputFileName;@
@
QString InputFileName;
Browse::Browse(QString input_filename, QWidget *parent) :
QDialog(parent)
{@
Then i use the following to test waiting loop of QDialog
@
oid Login::on_loginbrowse_clicked()
{
Browse * w = new Browse(dB_Setting);
w->show();
qDebug() << "return from browse";
}
@but when i click on browse, it prints return . It should wait till i select a file and then I should return the file name selected. I am still struggeling with it.
-
OK I found it, it should be
@
w->exec();
@and not
@
w->show();
@but how to return the value selected?
-
I've told you, if you use QDialog you can use your code:
@
oid Login::on_loginbrowse_clicked()
{
Browse w(this,dB_Setting);
w.exec();
qDebug() << "return from browse";
}
@ -
Or so... :)
You need filename value, right? Create function for getting this value:
@
public:
QString getValue(){return this->filename;}@
after dialog exits you can get your value like this:
@
void Login::on_loginbrowse_clicked()
{
Browse * w = new Browse(dB_Setting);
w->exec();
qDebug() << "return from browse: " << w->getValue();
//and don't forget to delete this instance:
delete w;
}
@ -
I have an issue over MAC. I need to show drives or at least to start with the current apppath folder
I used the following filter but I don't see drives, I have / only however when i loads, it shows volumes folder and the dissapears. I can not set the current path of the modelview to the current directory called set in AppPath QString.
@
dirmodel->setFilter(QDir::Dirs | QDir::Drives | QDir::NoDotAndDotDot | QDir::AllDirs);
@ -
Solved showing drives in MAC, since folder volumes is hidden, I used QDir::Hidden.
Although this is not the proper way but it is a bug in QT "Reported here":https://bugreports.qt-project.org/browse/QTBUG-6875@
dirmodel->setFilter(QDir::Dirs | QDir::Drives | QDir::Hidden | QDir::NoDotAndDotDot | QDir::AllDirs);
@ -
I have another question, I created a QDialog on the fly as this, then I want to differentiate between being closed normally with the (x) button or being closed through the ok button.
@
QDialog *modifypsswdwin = new QDialog (this);
QLabel *newpsd1 = new QLabel(this); newpsd1->setText("New password");
QPushButton *modifypsswdwin_ok = new QPushButton(this); modifypsswdwin_ok->setText("OK");
connect(modifypsswdwin_ok,SIGNAL(clicked()),modifypsswdwin,SLOT(close()));
int ret=modifypsswdwin.exec();
@I searched and found that I need to do
@
QDialog.setResult(1)
@but the question is how to setthe result if i have only 1 line in the connect. Is it possible to write multiple commands in the slot(close)?
thank you
-
I found it, we should connect accept to the button as well
connect(modifypsswdwin_ok,SIGNAL(clicked()),modifypsswdwin,SLOT(accept())); connect(modifypsswdwin_ok,SIGNAL(clicked()),modifypsswdwin,SLOT(close()));
-
I have a problem with the stylesheet. I use a style sheet file. I want to set a style sheet for this browse class from the file and not hardcoded. It works when it is hardcorded in the program but i don't know how to call it in the file. I tried #Browse and tried QDialogBox#Browse but did not work.
Any idea?