Unsolved How to disable 'x' close button
-
this->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint);
I tried this but it doesn't work. The reason why i want to disable it is because my app downloads files and if the user closes window 1 before the download finishes, window 2 lags and crashes. Only happens during download.
-
hi @nicholaslee
the easiest would probably be to overwride the close event. something like this:adjusted from the Application Example
void MainWindow::closeEvent(QCloseEvent *event) { if (downloadOngoing()) { event->ignore() } else { event->accept(); } }
-
@nicholaslee
when do you call this method exactly?What happens with this:
this->setWindowFlags( (Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint) & ~Qt::WindowCloseButtonHint );
-
@J-Hilk I just tried closeevent but oops i already used it and when i build it again qt says closeevent cannot be overloaded.
DownloaderUI::DownloaderUI(QWidget *parent) : QDialog(parent), ui(new Ui::DownloaderUI) { ui->setupUi(this); this->setWindowTitle(" Offline IVLE"); this->setWindowIcon(QPixmap(":/icons/OIVLE.png")); this->setWindowFlags( (Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint) & ~Qt::WindowCloseButtonHint );
I am calling it in my constructor when i setup the ui. My window title and icon works but the setwindowsflag does nothing. No difference in my app.
Thank you all for helping!
-
@nicholaslee
on what system are you actually on? -
@nicholaslee said in How to disable 'x' close button:
closeevent cannot be overloaded
You need to override it not overload
-
@raven-worx
I am on windows, qt5.0.2, creator 4.6.2.@jsulm @J-Hilk Noted. Actually how do I check if there is a downloadongoing? My download is set using a timer. Every hour it downloads. I tried to key in the code below, i added xxxx=1 at the top of my download function and xxxx=0 at the end of it. My app crashes instead.
void IVLEFetcher::closeEvent(QCloseEvent *event){ if (xxxx==0){ event->accept(); } else { if (xxxx==1){ event->ignore(); } } }
-
@nicholaslee said in How to disable 'x' close button:
My app crashes instead
Where does it crash? Did you debug?