Can't detect if widget/ui is visible
-
I've been trying to debug using qDebug() << dialog.isVisible() << endl; to determine if dialog show up whenever I click the button, but it always set to false even if it really is visible. How do I determine if the dialog is visible?
-
Can you show your code?
-
from mainwindow.cpp
void MainWindow::on_pushButton_clicked()
{
Dialog dialog(this);
dialog.setModal(true);
dialog.exec();
dialog.move(this->rect().center() - dialog.rect().center());
//dialog.setAttribute(Qt::WA_ShowWithoutActivating, true);
//dialog.setWindowFlags(/*Qt::Tool | / Qt::X11BypassWindowManagerHint /| Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint */);qDebug() << "Is Dialog visible from pushbutton: " << dialog.isVisible() << endl;
}
-
@LovelyGrace You're showing your dialog as modal (exec(), dialog.setModal(true); is not needed if you use exec()). That means when exec() finishes your dialog is not shown anymore!
You can try thisfrom mainwindow.cpp void MainWindow::on_pushButton_clicked() { Dialog *dialog = new Dialog(this); dialog.show(); dialog.move(this->rect().center() - dialog.rect().center()); qDebug() << "Is Dialog visible from pushbutton: " << dialog.isVisible() << endl; }
-
@LovelyGrace said in Can't detect if widget/ui is visible:
dialog.exec();
As @jsulm suggested you need to use
show()
because dialog will be in blocked state until user closes the dialog. You are checkingisVisible()
after you closed the dialog. Sodialog.isVisible()
returnsfalse
. -
how am I going to do this from another class but not in the mainwindow?? I tried this with calling the dialog class using Dialog *dialog; from the newDialog class private section: But it didn;t work, tried putting 'this' but error exist
void newDialog::startDialog()
{
Dialog dialog;
dialog.setModal(true);if(dialog.isVisible()) { qDebug() << "Dialog is Visible to newDialog Class" << endl; }
}
-
@LovelyGrace said in Can't detect if widget/ui is visible:
But it didn;t work
Can you show the code?
error exist
What is the error?
-
from the code above, no error exist, but it it didn't detect if the dialog is visible from the newDialog class
-
@LovelyGrace said in Can't detect if widget/ui is visible:
but it it didn't detect if the dialog is visible from the newDialog class
How are you doing it.
-
if you mean using this:
Dialog *dialog = new Dialog(this);the error says when I tried calling Dialog from newDialog class
error: no matching function for call -
@LovelyGrace said in Can't detect if widget/ui is visible:
error: no matching function for call
Can you show your
Dialog
class? -
@Ratzz mainwindow detect dialog class but newDialog can't
I tried calling Dialog class from the newDialog class and create a function from the newDialog class to test if it can detect the dialog when it runs, but it didn't. Using this code:
void newDialog::startDialog()
{
if(dialog.isVisible())
{
qDebug() << "Dialog is Visible to newDialog Class" << endl;
} -
@LovelyGrace said in Can't detect if widget/ui is visible:
if(dialog.isVisible())
Where do you use
show()
-
Hi,
@LovelyGrace said in Can't detect if widget/ui is visible:
void newDialog::startDialog()
{
Dialog dialog;
dialog.setModal(true);
if(dialog.isVisible())
{
qDebug() << "Dialog is Visible to newDialog Class" << endl;
}}
You haven't called show yet.
-
@LovelyGrace Did you make sure that show() was called?
-
@LovelyGrace said in Can't detect if widget/ui is visible:
@SGaist Hi show() function is in the mainwindow class, new Dialog class is supposed to check whether the dialog is running
I meant
dialog.show()
.The code you wrote will just create a dialog, and then destroy it since it's local to that method.
-
show() is running on the main window, what I want to happen is that newDialog will only detect if Dialog is running from the mainwindow and it's not supposed to show from the newDialog.
-
@LovelyGrace
If mainwindows knows if "Dialog" (bad class name) is shown or not and also shows newDialog when asked, why not let main window handle the logic ?Its seems odd that newDialog will show an other dialog if its not already on screen since its not the the one that put it there. Also if you open new dialog in newDialog, main window will not have access to that instance ( copy) and
cant tell if its open or not. -
how can i connect then the Dialog class to new Dialog class?