Results 1 to 4 of 4

Thread: Create new signal for derived widget

  1. #1
    Join Date
    Dec 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Create new signal for derived widget

    Hi.
    I wanted to make a check box widget which could emit a signal with an index whenever it's checked/unchecked.

    I made a new class derived from QCheckBox which contains a data member that holds the box's index.

    I want to override "stateChanged(int) signal to be "stateChabged(int,int)" so it will contain the index.

    I created a new signal in the Qt Designer (using the "edit" button in the Slots\Signals dialog).
    I added the overriding definition of the signal to the class header file.

    How do I proceed? Does the signal function has to have a body and if so what does it contain?

    The Qt assistant documentation is very lacking.

    Thank you.

  2. #2
    Join Date
    Dec 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Create new signal for derived widget

    Worked out a solution.
    Connected the original signal stateChanged(int) to slot animateClick(int).
    In the slot definition (.cpp) I emit my overridden signal using:

    Qt Code:
    1. void QCheckBoxCustom::animateClick(int state)
    2. {
    3. emit stateChanged(index, state); //index is a class data member
    4. }
    To copy to clipboard, switch view to plain text mode 


    Is there another way?

  3. #3
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Create new signal for derived widget

    You may be interested in QSignalMapper.

  4. #4
    Join Date
    Dec 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Create new signal for derived widget

    Okay, didn't know about that.
    Thank you.

Similar Threads

  1. Replies: 6
    Last Post: 3rd September 2008, 14:27
  2. Playbutton functionality
    By uchennaanyanwu in forum Qt Programming
    Replies: 5
    Last Post: 31st July 2008, 22:29
  3. Custom Widget - First Steps
    By sekatsim in forum Qt Programming
    Replies: 8
    Last Post: 26th June 2008, 17:19
  4. Custom Widget - clicked() signal
    By ak in forum Newbie
    Replies: 3
    Last Post: 13th November 2006, 08:35

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.