Results 1 to 7 of 7

Thread: changeEvent propagation, custom style changes

  1. #1
    Join Date
    Aug 2010
    Location
    Germany
    Posts
    54
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default changeEvent propagation, custom style changes

    How can I emit the changeEvent QEvent::StyleChange?

    I have a style class which includes extended style information for my application. This has nothing to do with the QStyle class itself, but contains information related to layout and appearance.

    What I want to do is make use of the "changeEvent" and send a StyleChange event when I modify this custom class. I see this as clearer than having a separate event for my custom style items. In most cases the widgets have to rebuild/paint themselves regardless of which style changed, so it makes sense.

    The documentation on changeEvent is rather sparse however. How can I propagate this message to all windows/widgets in the application?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: changeEvent propagation, custom style changes

    Did you read the QEvent documentation?
    In general, events come from the underlying window system (spontaneous() returns true), but it is also possible to manually send events using QCoreApplication::sendEvent() and QCoreApplication::postEvent() (spontaneous() returns false).
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Aug 2010
    Location
    Germany
    Posts
    54
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: changeEvent propagation, custom style changes

    Yes, I even indicated I read the documentation. "sendEvent" and "postEvent" require a specific receiver. Somehow normal changeEvents are propagated to all widgets in the system. That's the mechanism I'd like to use.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: changeEvent propagation, custom style changes

    AFAIK, no events are sent to all Widgets / Objects, rather, QApplication decides which events should go to which targets.(but I might be wrong with that)
    Some, are implicit, since they will be propagated between parents and children.
    If you want to send your event to all widgets in your application you could iterate through all your widgets using QApplication::allWidgets() or maybe QApplication::topLevelWidgets(). and put them as receiver for your postEvent()/sendEvent().
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Aug 2010
    Location
    Germany
    Posts
    54
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: changeEvent propagation, custom style changes

    I want to do whatever QT does when the style changes. However that propagates I'd like to do the same thing. Is there a function to do that? I could iterate over the top-level widgets, but I don't know how/if that event is forwarded.

  6. #6
    Join Date
    Aug 2010
    Location
    Germany
    Posts
    54
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: changeEvent propagation, custom style changes

    I looked at the source code and it appears on style changes QApplication simply iterates over allWidgets and sends the event directly, then calls an update on the widget. It skips items without the QA_SetStyle attribute.

    It's too bad they don't expose just this functionality, that'd make my code more future proof... I suppose I could just try setStyle( style() ) and hope it does it correctly.


    Added after 27 minutes:


    setStyle( style() ) doesn't work, since the style hasn't changed it does nothing. I guess I'll have to create my own loop.
    Last edited by mortoray; 26th October 2010 at 21:16.

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: changeEvent propagation, custom style changes

    setStyle( style() ) doesn't work, since the style hasn't changed it does nothing. I guess I'll have to create my own loop.
    Or override setStyle() to flag it the way you want, I think this would be simpler.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. protected function changeevent
    By fearu in forum Newbie
    Replies: 2
    Last Post: 25th September 2010, 13:11
  2. Some questions about custom style
    By charlse in forum Qt Programming
    Replies: 0
    Last Post: 2nd April 2009, 09:54
  3. Custom Style and Qt Designer 3
    By iukpo in forum Qt Tools
    Replies: 1
    Last Post: 23rd January 2007, 00:39
  4. ALT+TAB & changeEvent
    By munna in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2006, 19:15
  5. Custom Style
    By Dusdan in forum Qt Tools
    Replies: 8
    Last Post: 1st September 2006, 22:50

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.