Question

I am a total newbie to QT.

I am working with qt 4.7.1 on visual studio 2008.

I am trying to implement a button which is all covered by image, and when pressed, the image changes. (image-button) I am trying to use QT designer to put the button in currect layout then programmatically handle the pressed event (..signal..) to change the icon on the button.

create new mainWindow. put a tool button in it. switch to slots&signals mode. created a signal-slot from the button pressed() to new slot1() on the window. now where do I put the code of slot1()?

Was it helpful?

Solution

Sry for my english. It is rly bad, but I'll try to help you.

You have to use inheritance approach. So:
• you created a form, added a connection with slot1() on that form.
• include your form in project, compile it. A file named ui_FormName.h will be generated. At the bottom of that file you will find code like:
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui

You have to:
1) Create a new class, inherit from class QMainWindow.
2) In header include generated h-file, add a member of type Ui::MainWindow, which is declared in that generated .h-file (e.g.: Ui::MainWindow* m_puiTmp; ).
3) Also add code:
public slots: // or private slots:, or protected slots: ... Whatever.
void slot1();

then create implementation for functions in your new class. Don't forget to add m_puiTmp->setupUi( this ); in your constructor, and then create implementation for your slot1() slot.

You can also describe your slots and signals in derived class, and then connect them with signals and slots in QtDesigner. Simply when you adding a now slot or signal in designer, rename them in accordance with names, that you set in code.

Hope this will help you. If you can't solve your problem, write me a message. I'll try to help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top