Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, February 2007
How to disable the X button on windows?


Message 1 in thread

My users just found a stupid error on my part. If they click the "close
window" button it kills the app. I need it to close the window and
cancel what they were doing.

However, I can't seem to find out how to disconnect the current signals
and connect the ones I want. Thoughts or help?

Since that X button is window manager stuff does it end up being a
close() signal to the window or a quit() signal to the app. Or something
else?

--
 [ signature omitted ] 

Message 2 in thread

On 2/2/07, Allen, Matthew <allenm@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> My users just found a stupid error on my part. If they click the "close
> window" button it kills the app. I need it to close the window and
> cancel what they were doing.
>
> However, I can't seem to find out how to disconnect the current signals
> and connect the ones I want. Thoughts or help?
>
> Since that X button is window manager stuff does it end up being a
> close() signal to the window or a quit() signal to the app. Or something
> else?

The "X" button generates a QCloseEvent. You need to reimplement the
closeEvent() event handler.

-larry

--
 [ signature omitted ] 

Message 3 in thread

You can do that, 

	I think one of the QT examples has something like:

.hh:

class MyWindow: public QMainWindow
{
  Q_OBJECT
public:
	(...)
protected:
  void closeEvent(QCloseEvent *event);
};

.cc:
void MyWindow::closeEvent(QCloseEvent *event)
{
	if (it_is_ok_to_close)
	{
		event->accept();
	}
	else
	{
		event->ignore();
	}
}

					Regards,

							Nuno


On Friday 02 February 2007 12:17, Larry Martell wrote:
> > close() signal to the window or a quit() signal to the app. Or something
> > else?
>
> The "X" button generates a QCloseEvent. You need to reimplement the
> closeEvent() event handler.
-- 
 [ signature omitted ] 

Message 4 in thread

On 2/2/07, Allen, Matthew <allenm@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> My users just found a stupid error on my part. If they click the "close
> window" button it kills the app. I need it to close the window and
> cancel what they were doing.
>
> However, I can't seem to find out how to disconnect the current signals
> and connect the ones I want. Thoughts or help?
>
> Since that X button is window manager stuff does it end up being a
> close() signal to the window or a quit() signal to the app. Or something
> else?

Handle this by overriding QWidget::closeEvent(). Note that ignoring
the event will let you cancel the close attempt - see
http://doc.trolltech.com/4.2/mainwindows-application.html for an
example.

-- 
 [ signature omitted ]