//mainwindow.h
class ButtonLayout
: public QWidget {
Q_OBJECT
public:
public slots:
void openImage();
};
{
Q_OBJECT
public:
};
class ButtonLayout : public QWidget
{
Q_OBJECT
public:
ButtonLayout(QWidget *parent = 0);
public slots:
void openImage();
};
class ImageViewer : public QWidget
{
Q_OBJECT
public:
ImageViewer(QWidget *parent = 0);
};
To copy to clipboard, switch view to plain text mode
//mainwindow.cpp
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();
}
ButtonLayout::ButtonLayout(QWidget *parent)
: QWidget(parent)
{
QPushButton *btn1 = new QPushButton("IMAGE");
connect(btn1,SIGNAL(clicked()),this,SLOT(openImage()));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(btn1);
setLayout(layout);
}
ImageViewer::ImageViewer(QWidget *parent):QWidget(parent)
{
QLabel *lblImage = new QLabel;
QPixmap pixmap(QPixmap::fromImage(QImage(":/images/Resource/photo.JPG")));
lblImage->setPixmap(pixmap);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(lblImage);
setLayout(layout);
}
void ButtonLayout::openImage()
{
ImageViewer *viewer = new ImageViewer;
viewer->show();
}
To copy to clipboard, switch view to plain text mode
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...
Bookmarks