QProgressDialog don't show up in the front - qt

I have a QProgressDialog that needs to be popped up when application does the updates. It keeps hiding behind the windows.
dialog->setWindowTitle("Test");
QLabel * labl = new QLabel(this);
labl->setPixmap(QPixmap("icon.png"));
labl->setText("");
dialog->setLabel(labl);
dialog->setCancelButton(NULL);
dialog->show();
Am I doing something wrong here?

As a matter of fact you haven't provided enough information to solve the problem, my guess is you have forgotten to raise your dialog (because it was created and hidden earlier). So try to change the code to:
....
dialog->show();
dialog->raise();
dialog->activateWindow();
....

I had this same problem, when i had a modal QDialog and a QProgressDialog and the QDialog would always be on top despite the QProgressDialog coming from the QDialog itself. The issue was the lack of a parent assigned to QProgressDialog; just make sure that you assign the widget that spawns the QProgressDialog to be the parent.

Related

How can I use a QProgressDialog as a simple wait dialog without QProgressBar?

There is an operation in my application that can take up-to few minutes to finish. I wish to show a simple dialog box which opens when the operation begins, displays a simple wait message like 'Operation in progress..' and closes automatically when the operation finishes.
To implement above functionality, I am trying to make use of a QProgressDialog which does not have a QProgressBar. It seems to work fine but I am unable to set the wait message. Following is the code:
QProgressDialog progress(this);
QLabel *lblCustom = new QLabel(&progress);
progress.setBar(new QProgressBar());
progress.setValue(0);
progress.setLabel(lblCustom);
progress.setLabelText("Operation in progress. Please wait...");
progress.setMaximum(0);
progress.setMinimum(0);
progress.setModal(true);
progress.setWindowTitle("Validate field data");
progress.setCancelButton(0);
progress.setFixedSize(400, 100);
progress.setWindowFlags(progress.windowFlags() & ~Qt::WindowCloseButtonHint);
progress.show();
// operation
progress.close();
Setting label text does not seem to work. Please let me know what is wrong here? I am relatively new to Qt.
To solve the actual problem, I was used QLabel as a dialog instead of QProgressDialog and invoked QApplication::processEvents(), to make sure QLabel window gets painted with suitable text as well.
I suggest you create a new widget, then you can customize as you like. You can insert images and labels and you can create your own methods (including signals and slots). It will take a little longer to implement but it will be much more flexible and extensible.

How to start second QDialog window on side of MainWindow?

I have a application in Qt, and a MainWindow. Now, I also added a helping QDialog which can be hooked up. This QDialog does not influence the programmflow, it just displays information.
But, it always starts on top of the MainWindow :/
SO I would like to start it on the side of the main window, so that it does not hinder the view to the main window?? How?
In my opinion , You should try this,
Use the overload of the QWidget::setParent() function to change the ownership of a QDialog widget, using set as NULL(but It will not share the parent's taskbar entry).
QDialog::show() returns control to the caller immediately, So it will not interfere in mainwindow flow.
Let's say, your application is in the full screen mode. Where then the QDialog should appear? It will be shown on the top and you won't be satisfied again.
If it doesn't influence the flow of the app then you are using it to communicate some sort of message. Can you use different ways? For instance, QStatusBar?
If not, why not to split the mainWindow with QSplitter or similar classes and provide an area where you can post all the info messages?
It sounds you want modaless dialog. In main window, use a slot to create the dialog.
void MainWindow::show_dialog()
{
if ( pDialog== NULL )
pDialog= new XYZ_Dialog(this);
QPoint p = pos();
QSize s = frameSize();
pDialog->setGeometry(p.x()+s.width(), p.y(), s.width()*1/2, s.height());
pDialog->show();
}
What I try to say is if the position of the new dialog bothers you, you set the position and size of it, before showing it.

Qt Main window loosing focus and going to background unexpectedly

Going up the learning curve and everything has been making sense so far except for this one:
I have a main window from where I call one or more dialog like this:
d->setWindowFlags(Qt::CustomizeWindowHint | Qt::Window | Qt::FramelessWindowHint);
d->setGeometry(etc...
d->show();
The dialogs are not bound to the main window, and they are actually set to be displayed right beside the main window looking like an extension.
To close the dialogs I use a mouse 'enterEvent' on the mainwindow to send a close signal to the dialog(s) which will use hide().
void MainWidget::enterEvent(QEvent *event)
{
emit signal_related_close();
}
This works but randomly this causes a very annoying issue. When the signal is sent to close the dialogs, the main window would loose focus and go in the background (behind whatever application that is on the screen). Note that it does not minimize but only goes in the background and like I said it is random (about one out of 3 times I do it). I can't seem to get a pattern.
I initially thought the signal was messed up and instead used a dialog::leaveEvent() but that didn't help. I also tried using dialog::mouseMoveEvent and using that to hide the dialog but that would still randomly loose focus on the application.
The only method that doesn't loose focus is using a push button on each dialog that will initiate the same hide commands but that's not great for my UI. So it would seem that using the mouse enterEvent/leaveEvent,mouseMoveEvent will cause that random issue.
Anyone experienced this issue before? Any idea what could be wrong? Thx.
I can't explain why but this problem occurred when using QEvent or any mouse related event together with recursive children widgets. For example take this code in the parent widget constructor:
ChildWidget c1 = new ChildWidget (this);
ChildWidget c2 = new ChildWidget (c1);
Childwidget c3 = new ChildWidget (c2);
Using QEvent in the parent widget will randomly make the window go to the background and loose focus.
Setting all the ChildWidget to the same parent stopped the problem.

How do I hide QDialog that has Qt::WA_DeleteOnClose flag?

I have a QDialog that was created with Qt::WA_DeleteOnClose flag. When specific event happens I need to hide the dialog and restore it later upon another specific event. If I make a call to QWidget::hide() the dialog object is deleted (due to WA_DeleteOnClose) which doesn't work for me.
Unfortunately I can't unset/reset Qt::WA_DeleteOnClose in runtime for certain technical reasons.
The question is: how do I effectively hide QDialog so that it's not visible but still exists? I tried
QDialog* pDlg = ...;
QSizePolicy newSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
pDlg->setSizePolicy(newSizePolicy);
pDlg->setMinimumSize(0,0);
pDlg->resize(0,0);
but this didn't work. Might it be that I can move the dialog outside the desktop? Or...
I'm solely on Windows if it matters.
Thanks.

Qt negative button not working

In my Qt symbian app, I have over ride the negative exit button with back to come back on main screen and then again over ride it with exit to close the app, my app is working fine on emulator but when I test it on device it shows exit button instead of back, some time it shows back also but if I go to the same page twice then again it start showing exit button, frustrating part is that app is working fine on Qt emulator but not on device. Does somebody knows whats the problem is. I am using
back->setSoftKeyRole(QAction::NegativeSoftKey);
this->addAction(back);
to over ride the exit button before loading the screen and
back->setSoftKeyRole(QAction::NegativeSoftKey);
this->removeAction(back);
to removing back button when coming back to mainWindow.
Create vertical layout and Widget which You will add on scrollarea with parent as that class this e.g
QVBoxLayout *vlay = new QVBoxLayout(this);
QWidget *area = new QWidget(this)
And add widget to it
This will make it child of parent class.
works fine for me.
I think adding and removing QAction objects here and there is asking for problems.
You should try to redesign your application to use a QStateMachine to handle transitions between states.
Take a look at the introductory documentation here.
Refer this LINK for custom softkeys..
QAction* myAction= new QAction(tr("My Action"), this);
myAction->setSoftKeyRole(QAction::NegativeSoftKey);
addAction(myAction);

Resources