Solved Can't detect if widget/ui is visible
-
@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.
-
@SGaist Hi show() function is in the mainwindow class, new Dialog class is supposed to check whether the dialog is running
-
@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?
-
@LovelyGrace
well that you can also do from main window since it has both
pointers to the DialogClass and newDialogClassconnect( DialogClassPTR, SOMESIGNAL,newDialogClassPTR, SOMESLOT);
and also the other way if u need newDialog to talk to Dialog
-
What is your exact purpose with finding the visibility of that dialog ?
-
I will be making a function that only works if the dialog from the other class is visible or active.
-
mainwindow can now communicate with the newDialog, but why can't newDialog detect if Dialog is visible?
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 */);dialog = new Dialog(); dialog->show(); dialog->move(this->rect().center() - dialog->rect().center()); qDebug() << "Is Dialog visible from pushbutton: " << dialog->isVisible() << endl; nDialog = new newDialog(); nDialog->startDialog();
}
void newDialog::startDialog()
{
qDebug() << "DIALOG TO NEWDIALOG" << endl;
dialog = new Dialog();if(dialog->isVisible()) { qDebug() << "Dialog is Visible to newDialog Class" << endl; } if(dialog->isActiveWindow()) { qDebug() << "Dialog is Active to newDialog Class" << endl; }
}
The output is:
Is Dialog visible from pushbutton: true -- from mainwindowDIALOG TO NEWDIALOG -- from newDialog
-
@LovelyGrace
Hi is a brain bug. ;)You open and show "Dialog" in mainwindow.
Then in NewDialog
you create a yet other new "Dialog",
that you DO NOT show and then ask it if its visible. ( which its not)it will know NOTHING about the first dialog in main. the isVisible is pr copy u make.
if you really just mean to create the other new dialog in NewDialog then
void newDialog::startDialog() { qDebug() << "DIALOG TO NEWDIALOG" << endl; dialog = new Dialog(); dialog ->show(); ///////////////////////////// else it 100% wont be visible
- from main.
if you really want to do it this way
then
nDialog = new newDialog();
nDialog->startDialog(dialog); // give it the pointer to new dialog.
or
simeply tell it
nDialog->startDialog( dialog->isVisible() );// give a bool
so to repeat
You CANNOT create yet another copy of dialog to ask if the first copy u made in mainwindow is visible. - from main.