Results 1 to 6 of 6

Thread: [noob] How can I have a widget event call a function?

  1. #1
    Join Date
    Nov 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default [noob] How can I have a widget event call a function?

    I'm transitioning from Visual BASIC to Qt.

    Let's say I want to have a button change colour when it's clicked. How do I arrange for the click to trigger a function that changes its colour?

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

    Default Re: [noob] How can I have a widget event call a function?

    You need to use a feature called "signals and slots". Open Qt Assistant and enter "Signals and Slots" into the index tab.

  3. #3
    Join Date
    Nov 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [noob] How can I have a widget event call a function?

    OK, interesting...

    I connect my button's "clicked()" signal to its own "click()" slot, and I have myButton::click() change the colour? Or do I have to make a custom slot (and to do that do I need to make a custom "myQButton" class)?


    Basically, can I have my button change colour by editing only main.cpp and mainWidow.cpp?
    Last edited by Envergure; 25th November 2008 at 17:07.

  4. #4
    Join Date
    Jul 2006
    Location
    Atlanta, GA
    Posts
    86
    Thanks
    26
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [noob] How can I have a widget event call a function?

    http://doc.trolltech.com/4.4/index.html is your best friend. I use it on a daily basis.
    fnmblot
    --------------------------------------
    Gee Ricky, I'm sorry your mom blew up.

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

    Default Re: [noob] How can I have a widget event call a function?

    You need to create your own custom slot somewhere (like in mainWindow.cpp) and connect the signal to it. Inside the slot you need to perform the changes you want.

  6. #6
    Join Date
    Nov 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [noob] How can I have a widget event call a function?

    Yay, it's working!

    I had to call my button by "ui.pushButton" instead of just "pushButton". Otherwise I got "pushButton not declared in this scope."

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 15:22
  2. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 13:57
  3. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 18:33
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 13:52

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.