Results 1 to 6 of 6

Thread: Blacking out the screen

  1. #1
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Blacking out the screen

    My client wants something artsy. The application has a screen full of widgets. If the user clicks the "X" go-away button they want the main screen to be over laid with a 85% semi-transparent black, and have an "Are You Sure?" dialog appear.

    I have the dialog working just fine, but my black overlay is not working. Probably due to a trivial newbie mistake.

    The situation is that the main window contains a single QStacked widget, each page of which contains a complicated QWidget composed of numerous controls. In the main window I have sub-classed closeEvent(). This is the code I'm using to vainly to apply an 85% black:
    Qt Code:
    1. int theIndex = m_stackedWidget->currentIndex();
    2. QWidget *currentWidget = m_stackedWidget->widget(theIndex);
    3. QWidget *crepuscularWidget = new QWidget(currentWidget);
    4. crepuscularWidget->resize(currentWidget->size());
    5. QPainter painter(crepuscularWidget);
    6. painter.setOpacity(0.85);
    7. painter.fillRect(crepuscularWidget->rect(), QBrush(Qt::black));
    8. crepuscularWidget->repaint();
    9. // then follows the code to put up the "Are You Sure?" modal dialog
    To copy to clipboard, switch view to plain text mode 
    Originally this was more compact, I've expanded it to aid debugging (e.g., the first line used to end in = m_stackedWidget->widget(m_stackedWidget->currentIndex()))

    It doesn't work.

    I've tried initializing crepuscularWidget with the main window, stackedWidget, as well as m_stackedWidget->widget(n). I've tried not using crepuscularWidget at all, instead initializing painter with the main window, stackedWidget, and m_stackedWidget->widget(n). I've used crepuscularWidget->repaint() and crepuscularWidget->update(). Nothing seems to work.

    Can anybody see what I am doing wrong?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Blacking out the screen

    You have to call show() on the new widget .

  3. #3
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Blacking out the screen

    Alas, I put in a crepuscularWidget->show() right before the crepuscularWidget->repaint(), but it had no effect. It still is not drawing. Thanks for the suggestion anyway, it was stupid of me to forget the show().

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Blacking out the screen

    Oh... What was I thinking...
    You can't paint a widget outside its paintEvent...

    So, there's your reason.

  5. The following user says thank you to marcel for this useful post:

    WinchellChung (19th March 2008)

  6. #5
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Blacking out the screen

    Ah, that would certainly do it. Thank you very much!

  7. #6
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Blacking out the screen

    Yes, I moved the drawing code into the CrepuscularWidget's paintEvent, and it is working perfectly. Thank you very much!

Similar Threads

  1. Setting manually cursor position on multi screen systems
    By irreriwan in forum Qt Programming
    Replies: 0
    Last Post: 4th March 2008, 09:47
  2. multi screen
    By Thomas Feldman in forum Qt Programming
    Replies: 5
    Last Post: 9th May 2007, 16:41
  3. QTimer based Splash Screen
    By bpetty in forum Newbie
    Replies: 6
    Last Post: 15th December 2006, 00:51
  4. hiding mouse on second screen
    By safknw in forum KDE Forum
    Replies: 1
    Last Post: 24th November 2006, 11:09
  5. Problem with screen update...
    By mysearch05 in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2006, 18:24

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.