Results 1 to 4 of 4

Thread: how to create own event?

  1. #1
    Join Date
    Jul 2019
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default how to create own event?

    Hello there,

    I want to create own event, there is a real button and get "1","0" signal from it. If push the button, i will get signal 1 and then i will change text color. How can i do that

    This problem seems like basic but how can i check real button's state continuously? i need to create event like pushButton.clicked.connect(). it will work only when the actual button is pressed.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,454
    Thanked 271 Times in 266 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to create own event?

    What does it mean "there is a real button" ? Is it a hardware button ?

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,053
    Thanks
    233
    Thanked 649 Times in 639 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: how to create own event?

    i need to create event like pushButton.clicked.connect()
    This is not an "event".

    Are you saying that you have a real, physical button that a human pushes with her finger, and you want to detect that press with your program? I assume you are still using a RasPi as you mentioned in your previous post.

    First, you need to use the functions of python on the RasPi to detect the physical state change of the button. There are many examples for how to detect contact closures using the input pins of the Pi. I am not sure if you need to monitor the button state continuously or whether the Pi can send an interrupt to your program when the state changes. If you cannot use an interrupt, then I would suggest you use a QTimer to check the button every 100 ms or so in a slot connected to the QTimer's timeout() signal. If you write a loop to continually check the state, then your program will freeze in the loop.

    You should implement the code for responding to the button press in a class derived from QObject. Classes based on QObject have the ability to send signals. In your class, you should implement a signal that will be emitted when the button changes state. You should also be able to find examples of how to implement a custom signal in your PyQt documentation. You can then connect this signal to any other part of your program that needs to know when the button has been pressed.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Jul 2019
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to create own event?

    Thank you so much,sir. Thats working.

Similar Threads

  1. how to create click event dynamically???
    By Radhika in forum Qt Programming
    Replies: 2
    Last Post: 21st December 2015, 09:03
  2. how to manually create touch event?
    By harshita in forum Qt Programming
    Replies: 4
    Last Post: 9th September 2011, 12:10
  3. class and event create
    By electronicboy in forum Qt Programming
    Replies: 2
    Last Post: 1st November 2009, 23:07
  4. create mouse click event problem
    By yagabey in forum Qt Programming
    Replies: 6
    Last Post: 8th October 2009, 21:45
  5. Create new an event, help me?
    By dungsivn in forum Qt Programming
    Replies: 6
    Last Post: 4th July 2007, 11:22

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.