Results 1 to 6 of 6

Thread: Acessing a widget's mouse event that was declared localy and smoothing

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Acessing a widget's mouse event that was declared localy and smoothing

    Hello!

    In one of my applications, I want that some QWidgets with some labels appear in the desktop when a given signal is emitted, while this QWidgets should have the same functionality of the messages from a QSystemTrayIcon: if the user clicks on them, the widget dissapear. This all with a notice: I prefer not the create a QWidget subclass in a new .cpp and .hpp and .ui files; I'ld like to creates them inside the slot connected to the signal, if possible.

    There are two questions I would like to do regarding this situation:

    1º: how may I program the code in order for the tracking of the on click QMouseEvent to work, closing the QWidget? I know that, if I create a new class, I would just have to reimplement the mouseEvent(QMouseEvent*), but remember that I'ld like to do this directly by coding in the slot.
    2º: in this same situation, how to add a smooth¹ event both when the widgets is appearing as well as when it dissapears after a click on it is made?


    Thanks,

    Momergil

    ¹: not sure if this is the appropriate word... By that I mean that the widget will not appear suddently on the screen, but gradually, like the messages from QSystemTrayIcon do.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Acessing a widget's mouse event that was declared localy and smoothing

    For 1. you can install event filter on the newly created widget.
    For 2., I don't know how to implement this without reimplementing widget's paintEvent.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Acessing a widget's mouse event that was declared localy and smoothing

    Quote Originally Posted by Momergil View Post
    This all with a notice: I prefer not the create a QWidget subclass in a new .cpp and .hpp and .ui files
    Can we ask why? Is this some obscure C++ contest where the purpose is to make the code as unreadable as possible?
    Or a contest where the goal is to use as few files as possible?

    Cheers,
    _

  4. #4
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Acessing a widget's mouse event that was declared localy and smoothing

    Hello anda_skoa,

    the second option Or more precisely, the problem is that my project has already up to 30 cpp/hpp/ui files, what makes it quite poluted, so I prefer to use the files for more difficult dialogs/windows while keeping small and less difficult classes to "direct code".

    stampede,

    thanks. I guess, then, I'll have to create a new class that implements QWidgets and adds both event filter and paintEvent.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Acessing a widget's mouse event that was declared localy and smoothing

    If you want animations then QPropertyAnimation is your friend. You can combine it with window opacity to try to achieve the effect you want.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    Momergil (10th January 2014)

  7. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Acessing a widget's mouse event that was declared localy and smoothing

    Quote Originally Posted by Momergil View Post
    the second option Or more precisely, the problem is that my project has already up to 30 cpp/hpp/ui files, what makes it quite poluted, so I prefer to use the files for more difficult dialogs/windows while keeping small and less difficult classes to "direct code".
    You can use subdirectories in Qt projects to organize files.

    But if you prefer messing up your code, go for it

    Cheers,
    _

Similar Threads

  1. Mouse Move event not functioning in Qscrollarea in tab widget
    By sandeep.theartist in forum Qt Programming
    Replies: 1
    Last Post: 11th July 2012, 08:29
  2. Mouse event handling beyond/outside the widget
    By keyur259 in forum Qt Programming
    Replies: 7
    Last Post: 20th January 2010, 05:14
  3. Replies: 7
    Last Post: 14th January 2010, 08:47
  4. pass mouse event information to another widget
    By Rooster in forum Qt Programming
    Replies: 5
    Last Post: 12th July 2008, 04:23
  5. Replies: 10
    Last Post: 12th February 2007, 17:30

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.