View Single Post
Venemo's Avatar
Posts: 1,290 | Thanked: 1,753 times | Joined on Aug 2009 @ Budapest, Hungary
#41
Originally Posted by mikhas View Post
http://doc.trolltech.com/4.6/qwidget.html#closeEvent

Reimplement this event handler to ignore the close event on a certain condition. Also see the example which explains why this can be useful.
Thanks!

I'll post the solution here, in case anyone else wants it. It bugs me though, that it can't be done without creating a derived class.

Code:
#ifndef UNCLOSEABLEMESSAGEBOX_H
#define UNCLOSEABLEMESSAGEBOX_H

#include <Qt>
#include <QtGui>
#include <QtCore>

class UncloseableMessageBox : public QMessageBox
{

public:

    UncloseableMessageBox(const QString& title, const QString& text, Icon icon, QWidget *parent = NULL) : QMessageBox(icon, title, text, QMessageBox::Ok, parent)
    {
        this->button(QMessageBox::Ok)->hide();
    }

    void closeEvent(QCloseEvent *event)
    {
        event->ignore();
    }

};

#endif // UNCLOSEABLEMESSAGEBOX_H
If anyone finds a mistake, I'd appreciate it if you tell me.
 

The Following User Says Thank You to Venemo For This Useful Post: