PDA

View Full Version : Window Modality question



zgulser
22nd May 2009, 10:58
Hi,

I have a QMainWindow in which I drive my application. Sometimes I need to display some warning messages in my application and what I want is to disable any input receiving for all of the widgets(widgets inside the mainwindow) but a warning message dialog whenever it appears.

In order to do that, I set the window modality for my warning message widget whenever it appears but the problem is, when I do that I also disable the dialog itself.

Is there a way to do this?

Thanks in advance

zgulser
22nd May 2009, 11:26
Problem solved by adding


setAttribute(Qt::WA_KeyCompression);

faldzip
22nd May 2009, 11:34
how do you create and show your message window? Does it inherit from QDialog? I've read the docs and I don't see any connection between modality and key compression...

zgulser
22nd May 2009, 12:44
hi,

that's just a widget. If you read the docs I suggest you to look at QtGui module again. perhaps, you have missed it. the connection is that once you set your widget as modal, you have to do bonus work since my widget is not another mainwindow definitely.this is where the KeyCompression has to be taken into account.

regards

zgulser
22nd May 2009, 14:31
Ooops!

The solution I've found seemed to work at the begining but it doesn't work at all now.

Any ideas regarding my very first thread message?

aamer4yu
23rd May 2009, 13:38
Can we see the code how you set modality ?

faldzip
23rd May 2009, 21:14
hi,

that's just a widget. If you read the docs I suggest you to look at QtGui module again. perhaps, you have missed it. the connection is that once you set your widget as modal, you have to do bonus work since my widget is not another mainwindow definitely.this is where the KeyCompression has to be taken into account.

regards

Ok, can you provide some link to the docs where there is anything about modality connected with key compression? I just can't understand it... :/
What I found about KeyCompression:


Enables key event compression if set, and disables it if not set. By default key compression is off, so widgets receive one key press event for each key press (or more, since autorepeat is usually on). If you turn it on and your program doesn't keep up with key input, Qt may try to compress key events so that more than one character can be processed in each event. For example, a word processor widget might receive 2, 3 or more characters in each QKeyEvent::text(), if the layout recalculation takes too long for the CPU. If a widget supports multiple character unicode input, it is always safe to turn the compression on. Qt performs key event compression only for printable characters. Qt::Modifier keys, cursor movement keys, function keys and miscellaneous action keys (e.g. Escape, Enter, Backspace, PrintScreen) will stop key event compression, even if there are more compressible key events available. Platforms other than Mac and X11 do not support this compression, in which case turning it on will have no effect. This is set/cleared by the widget's author.
And about WindowModality:

This property holds which windows are blocked by the modal widget.

This property only makes sense for windows. A modal widget prevents widgets in other windows from getting input. The value of this property controls which windows are blocked when the widget is visible. Changing this property while the window is visible has no effect; you must hide() the widget first, then show() it again.

By default, this property is Qt::NonModal.
So I understand that KeyCompression is used when your widget can't keep up with key events... So what do you have in your modal window? Advanced word processor?

I suggest you doing like this to show your widget as modal (let's say it's called MyWidget):


// in slot which is supposed to show the widget - or sth like that
MyWidget *widget = new MyWidget(this);
QDialog dlg(this);
QVBoxLayout layout(&dlg);
layout->addWidget(widget);
dlg.setLayout(layout);
dlg.exec();

zgulser
25th May 2009, 08:11
Can we see the code how you set modality ?

First of all, my dialog is a separate ui file, not a QDialog thing. So it's a new class called MessageDialogs. I sticked with this way instead of using QDialog for particular project reasons.

Anyway..What I did is - just creating an instance of the MessageDialogs( let's call it myMessageDialog) and typing myMessageDialog->setWindowModality(Qt::ApplicationModal);

zgulser
25th May 2009, 11:17
This property holds which windows are blocked by the modal widget.

This property only makes sense for windows. A modal widget prevents widgets in other windows from getting input. The value of this property controls which windows are blocked when the widget is visible. Changing this property while the window is visible has no effect; you must hide() the widget first, then show() it again.

By default, this property is Qt::NonModal.

Come on..I know this. I just got a little bit confused:). So I looked at what you suggest me at the end of your message but I as mentioned in my most previous message I don't wanna use QDialog. If I repeat the problem;

I couldn't reach the message widget ,which appears in the front of the application upon a button click, since I prevent his parent to receive any inputs by setting window modality to my message widget. Is there a way to solve this?

faldzip
25th May 2009, 11:29
what's the point of NOT using QDialog if what you want to do is exactly what QDialog DOES and it gives you for free?

P.S. and can you show us more code? I don't have any problem in setting my widget application modal:


Form *form = new Form;
form->setWindowModality(Qt::ApplicationModal);
form->show();

zgulser
25th May 2009, 12:36
what's the point of NOT using QDialog if what you want to do is exactly what QDialog DOES and it gives you for free?

Because my dialog box has many particular cosmetic differences due to my project description and that's why couldn't provide more code:/. I hope the following lets you understand the case more clearly.


mMessageDialogs.reset(new MessageDialogs(this->parentWidget(),1,1,"WARNING","blablabla"));
mMessageDialogs->hide();
mMessageDialogs->setWindowModality(Qt::ApplicationModal);
mMessageDialogs->move(this->x()+100,this->y()+300);
mMessageDialogs->show();

faldzip
25th May 2009, 12:44
and what if you set parent = 0?