Results 1 to 8 of 8

Thread: Qt5 native messages not propogated?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Qt5 native messages not propogated?

    I use Qt 4.8 with SFML 2.0, but I just migrated to Qt 5.0. I'm programming on Windows 7, 32 bit, and I use MinGW (4.7.2) as my compiler.

    The basic layout of my application is a QWidget as the "main window", with several QWidget side panels, and in the center, a QWidget mixed with SFML ("sfml window"), that SFML draws and handles events for.

    In Qt 4.8, SFML keyboard events for that central SFML window worked just fine, but in Qt 5.0, the keyboard events aren't reaching SFML. The keyboard events are reaching the QWidget that SFML is attached to (I breakpointed on keyPressEvent() to test), but SFML's keyboard events stopped working in Qt 5. Not all events, mouse events work fine, but the keyboard events don't get forwarded to SFML by Qt.

    I even tried to grabKeyboard() on the QWidget/SFML window to check. Didn't help.
    Qt Code:
    1. class AreaWindow : public QWidget, public sf::RenderWindow
    2. {
    3. Q_OBJECT
    4. public:
    5. AreaWindow();
    6. ~AreaWindow();
    7.  
    8. //...other functions...
    9. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. AreaWindow::AreaWindow()
    2. : QWidget(nullptr), isInitialized(false)
    3. {
    4. //Setup some states to allow direct rendering into the widget
    5. QWidget::setAttribute(Qt::WA_PaintOnScreen);
    6. QWidget::setAttribute(Qt::WA_OpaquePaintEvent);
    7. QWidget::setAttribute(Qt::WA_NoSystemBackground);
    8. QWidget::setAttribute(Qt::WA_PaintUnclipped);
    9.  
    10. //Set strong focus to enable keyboard events to be received
    11. QWidget::setFocusPolicy(Qt::StrongFocus);
    12. }
    13.  
    14. void AreaWindow::showEvent(QShowEvent*)
    15. {
    16. if(!this->isInitialized)
    17. {
    18. //Under X11, we need to flush the commands sent to the server to ensure that
    19. //SFML will get an updated view of the windows
    20. #ifdef Q_WS_X11
    21. XFlush(QX11Info::display());
    22. #endif
    23.  
    24. //Create the SFML window with the widget handle
    25. sf::RenderWindow::create((HWND)this->winId());
    26.  
    27. this->isInitialized = true;
    28. }
    29. }
    30.  
    31. QPaintEngine *AreaWindow::paintEngine() const
    32. {
    33. //We make the paintEvent function return a null paint engine. This functions works together with
    34. //the WA_PaintOnScreen flag to tell Qt that we're not using any of its built-in paint engines.
    35. return nullptr;
    36. }
    37.  
    38. void AreaWindow::paintEvent(QPaintEvent *event)
    39. {
    40. //Clear the window (using SFML).
    41. sf::RenderWindow::clear(Global::Window::ClearColor.ToSfmlColor());
    42.  
    43. //Start the camera off on World mode.
    44. this->SetCameraMode(CameraMode::World);
    45.  
    46. //...draw code goes here...
    47.  
    48. //Display on screen (using SFML).
    49. sf::RenderWindow::display();
    50. }
    To copy to clipboard, switch view to plain text mode 

    To be clear, this worked in Qt 4.8 - some change between Qt 4.8 and Qt 5.0 stopped native Win32 keyboard events from being forwarded to SFML. Any ideas?

    [Edit:] SFML also isn't receiving the focus/unfocus events (sf::Event::GainedFocus and sf::Event::LostFocus), even though the QWidget is (QWidget::focusInEvent(), QWidget::focusOutEvent()).
    This is not an SFML-related problem, the QWidget is stopping the Win32 events (it seems to me).
    Last edited by ComServant; 27th December 2012 at 17:13. Reason: updated contents

Similar Threads

  1. Get Windows Messages
    By METEOR7 in forum Qt Programming
    Replies: 7
    Last Post: 2nd January 2012, 17:27
  2. Printing Messages Only once
    By purplecoast in forum Qt Programming
    Replies: 0
    Last Post: 3rd October 2010, 21:15
  3. Getting messages sent by PostMessage
    By Luc4 in forum Qt Programming
    Replies: 5
    Last Post: 19th May 2010, 16:13
  4. Qt4 no debug messages
    By TheKedge in forum Newbie
    Replies: 3
    Last Post: 23rd January 2006, 17:52

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.