Results 1 to 3 of 3

Thread: accesing events in another widget

  1. #1
    Join Date
    Jul 2009
    Posts
    12
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default accesing events in another widget

    Hello.. i have a question and i think you can help me.
    I have a stacked widget that loads two different widgets.
    On each widget i have a button that if i press i want to interchange the two widgets(something like widget1 swap to widget2).
    Do you have any advice as to how to acces and figure out that the button was pressed?
    The swaping is made in the mainwindow, but the button is in two different widget-classes.
    Thank you.

  2. #2
    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: accesing events in another widget

    Use signal and slots with either QSignalMapper or QObject::sender().

    For example:
    Qt Code:
    1. QSignalMapper *mapper = ...
    2. QPushButton *buttonOne = ...
    3. QPushButton *buttonTwo = ...
    4. mapper->setMapping(buttonOne, 0);
    5. mapper->setMappinc(buttonTwo, 1);
    6. connect(buttonOne, SIGNAL(clicked()), mapper, SLOT(map()));
    7. connect(buttonTwo, SIGNAL(clicked()), mapper, SLOT(map()));
    8. connect(mapper, SIGNAL(mapped(int)), stackedWidget, SLOT(setCurrentIndex(int)));
    To copy to clipboard, switch view to plain text mode 
    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.


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

    andreime (19th July 2009)

  4. #3
    Join Date
    Jul 2009
    Posts
    12
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: accesing events in another widget

    thank you a lot it solved many problems

Similar Threads

  1. Replies: 2
    Last Post: 21st June 2009, 06:04
  2. resizing events of a custom widget in a layout
    By Rooster in forum Qt Programming
    Replies: 7
    Last Post: 16th February 2008, 10:52
  3. Determining when mouse over widget without events
    By Kimmo in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2007, 10:48
  4. Handling Mouse Events of a parent widget
    By dvmorris in forum Qt Programming
    Replies: 2
    Last Post: 28th March 2007, 18:44
  5. Forwarding mouse events to another widget.
    By yogeshm02 in forum Qt Programming
    Replies: 8
    Last Post: 28th February 2006, 13:25

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.