How to hide the current window and then cut screen.
-
Hi everyone!
I'm a new member of forum and I'm a beginner with Qt. I searched in forum if somebody else had the same problem, but there is no such result.
My problem is the following:
(1) I want to cut screen after this windows has hidden, but sometimes the windows has not hide completed.
Delay 10 millisecond is a temporary solution, but sometimes this problem reappear. Is there a better way that can hide the window exactly ?
(2) The ScreenCutDialog can not get Focus because the current window is minimized, when the last active window is belonged to other programs, cause that no-responsey when press "ESC" key . Is there any Solution?I have tried a lot of methods, but no results, thank you. Best regards !
@
void CChatInput::slot_OnSnap()
{
if(isSnapHide()) // if true, this window should minimize before cut screen
{
slot_minimizeDialog(); // hide the dialog
//QEventLoop eventLoop;
//QTimer::singleShot(10,&eventLoop,SLOT(quit())); //delay 10 millisecond
//eventLoop.exec();
}
cutScreen();
slot_activeDialog(); //active the parent window
}void CChatInput::cutScreen()
{
ScreenCutDialog dlg; //
if (dlg.exec() == QDialog::Accepted)
{
//... ...
}
}void CChatInput::slot_minimizeDialog()
{
QWidget* ppp = CommonFun::getTopParentWidget(this); // get current windowif (ppp!=NULL)
{
ppp->showMinimized();
}
}
@
@
void ScreenCutDialog::keyPressEvent(QKeyEvent *event)
{
QDialog::keyPressEvent(event);
if (event->key() == Qt::Key_Escape)
{
reject();
}
}@ -
I think you can use @ void QWidget::hideEvent(QHideEvent * event) @ to detect when window is hidden. rewrite this function and cut window here.
-
Thank you, I tried this way before I asked in this Forum, but didn't work. The Area that hasn't hidden is the part overlap other windows. It means that, the windows hasn't hidden completely, and the ScreenCutDialog can cut the part that overlap other windows.
-
Thank you, I tried this way before I asked in this Forum, but didn’t work. The Area that hasn’t hidden is the part overlap other windows. It means that, the windows hasn’t hidden completely, and the ScreenCutDialog can cut the part that overlap other windows.
[quote author="mehrdadsilver" date="1381575639"]I think you can use @ void QWidget::hideEvent(QHideEvent * event) @ to detect when window is hidden. rewrite this function and cut window here.[/quote] -
Thanks for mehrdadsilver . The second problem that no-responsey when press “ESC” key hava solved. I use activeWindow() to make the ScreenCutDialog hava focus. I use the way that Delay 50 millisecond as a temporary solution to reduce the probability of window hidden endless.
-
Hi,
instead of minimizing your window, why don't you use "QWidget::hide()":http://qt-project.org/doc/qt-5.1/qtwidgets/qwidget.html#hide?