Results 1 to 12 of 12

Thread: Window Modality question

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Window Modality question

    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

  2. #2
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Window Modality question

    Problem solved by adding


    setAttribute(Qt::WA_KeyCompression);

  3. #3
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Window Modality question

    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...
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  4. #4
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Window Modality question

    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

  5. #5
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Window Modality question

    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?

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Window Modality question

    Can we see the code how you set modality ?

  7. #7
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Window Modality question

    Quote Originally Posted by zgulser View Post
    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):
    Qt Code:
    1. // in slot which is supposed to show the widget - or sth like that
    2. MyWidget *widget = new MyWidget(this);
    3. QDialog dlg(this);
    4. QVBoxLayout layout(&dlg);
    5. layout->addWidget(widget);
    6. dlg.setLayout(layout);
    7. dlg.exec();
    To copy to clipboard, switch view to plain text mode 
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  8. #8
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Window Modality question

    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);

  9. #9
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Window Modality question

    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?

  10. #10
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Window Modality question

    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:
    Qt Code:
    1. Form *form = new Form;
    2. form->setWindowModality(Qt::ApplicationModal);
    3. form->show();
    To copy to clipboard, switch view to plain text mode 
    Last edited by faldzip; 25th May 2009 at 10:43.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  11. #11
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Window Modality question

    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.

    Qt Code:
    1. mMessageDialogs.reset(new MessageDialogs(this->parentWidget(),1,1,"WARNING","blablabla"));
    2. mMessageDialogs->hide();
    3. mMessageDialogs->setWindowModality(Qt::ApplicationModal);
    4. mMessageDialogs->move(this->x()+100,this->y()+300);
    5. mMessageDialogs->show();
    To copy to clipboard, switch view to plain text mode 

  12. #12
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Window Modality question

    and what if you set parent = 0?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. How to set Qt window transparent?
    By montylee in forum Qt Programming
    Replies: 17
    Last Post: 24th December 2013, 20:11
  2. Set a window as child at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2007, 09:30
  3. Change shape of window / animate window
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 31st October 2007, 08:16
  4. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41
  5. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 10:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.