How to declare a function for click button event
//mainwindow.h
Code:
class ButtonLayout
: public QWidget {
Q_OBJECT
public:
public slots:
void openImage();
};
{
Q_OBJECT
public:
};
//mainwindow.cpp
Code:
ButtonLayout
::ButtonLayout(QWidget *parent
) {
connect(btn1,SIGNAL(clicked()),this,SLOT(openImage()));
layout->addWidget(btn1);
setLayout(layout);
}
{
lblImage->setPixmap(pixmap);
layout->addWidget(lblImage);
setLayout(layout);
}
void ButtonLayout::openImage()
{
ImageViewer *viewer = new ImageViewer;
viewer->show();
}
I have declared two classes for it to show a image when I press the Image button...Can I declare these things in one class...
Re: How to declare a function for click button event
How about you edit your post to put [code] tags around the code like Denis Kormalev did for you in whatever forum you cut and paste this from.
The answer to your question is yes, you can do this with only one class. Just construct and show() the QWidget in the openImage() slot.
Re: How to declare a function for click button event
thanks for your reply....can you please elaborate....
Re: How to declare a function for click button event
Put the code from your ImageViewer constructor into the openImage() slot directly.
Re: How to declare a function for click button event
Code:
void ButtonLayout::openImage()
{
titleWidget
->setObjectName
(QString::fromUtf8("IMAGE"));
titleWidget->show();
lblImage->setPixmap(pixmap);
layout->addWidget(titleWidget);
layout->addWidget(lblImage);
setLayout(layout);
}
------------OR-------------
Code:
void ButtonLayout::openImage()
{
lblImage->setPixmap(pixmap);
layout->addWidget(lblImage);
setLayout(layout);
}
I have tried in this type but it is not showing Image....
Re: How to declare a function for click button event
The second time, we have [code] tags here. So please edit your post and add them.
Further what is the need to construct a QImage and immediately convert it to a QPixmap. You also want spend some time and get familiar with layouts, how to use them and where you have to apply them. Start with the documentation.
Re: How to declare a function for click button event
how should I edit these tags...I already used @ tags but its not working ,what I hav to put before these tags ???
Re: How to declare a function for click button event
E.g.:
[code]int i = 0;
i++;
if (i == 1)
quit();[/code]
Re: How to declare a function for click button event
Code:
class ButtonLayout
: public QWidget {
Q_OBJECT
public:
//add remaining class members
};
ButtonLayout
::ButtonLayout(QWidget *parent
) {
connect(btn1,SIGNAL(clicked()),this,SLOT(openImage()));
layout->addWidget(btn1);
setLayout(layout);
//add like this
lblImage->setPixmap(":/images/Resource/photo.JPG");
}
void ButtonLayout::openImage()
{
lblImage->show();
}
it all depends on ur need. as our Qt experts said, u should start studying QtDoc
Bala