Hi
I'm trying to create very simple (training) program for viewing pictures. The idea is to create application with one window that contains one button and another widget to paint the picture on it. So when i click the button image appears in designated area. Now, I have created class "paintarea" then I put QWidget on the form and promoted that widget to "paintarea". And that is where I got stuck. I don't know how to connect the QPushButton that is on the QMAinWIndow "form", with that promoted widget, so that if I click the button, then the signal sends a message to custom widget with fileName to be loaded ?? I hope I didn't confuse You to much. Below is my code of this app. All help will be very appreciated. Sorry for poor english.
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <QPushButton>
namespace Ui
{
class mainwindow;
}
{
Q_OBJECT
public:
~mainwindow();
private:
Ui::mainwindow *ui;
public slots:
void send_signal();
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <QPushButton>
namespace Ui
{
class mainwindow;
}
class mainwindow : public QMainWindow
{
Q_OBJECT
public:
mainwindow(QWidget *parent = 0);
~mainwindow();
private:
Ui::mainwindow *ui;
QPushButton *button;
public slots:
void send_signal();
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
mainwindow
::mainwindow(QWidget *parent
){
ui->setupUi(this);
button = ui->button;
connect (button,SIGNAL (clicked()),this,SLOT (send_signal()));
}
mainwindow::~mainwindow()
{
delete ui;
}
void mainwindow::send_signal()
{
paint_space->load_image("/home/xxx/picture.jpeg");
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
mainwindow::mainwindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::mainwindow)
{
ui->setupUi(this);
button = new QPushButton;
button = ui->button;
connect (button,SIGNAL (clicked()),this,SLOT (send_signal()));
}
mainwindow::~mainwindow()
{
delete ui;
}
void mainwindow::send_signal()
{
paint_space->load_image("/home/xxx/picture.jpeg");
}
To copy to clipboard, switch view to plain text mode
paintarea.h
#ifndef PAINTAREA_H
#define PAINTAREA_H
#include <QWidget>
#include <QPainter>
#include <QPixmap>
{
Q_OBJECT
public:
void load_image
(const QString &fileName
);
protected:
bool status;
};
#endif // PAINTAREA_H
#ifndef PAINTAREA_H
#define PAINTAREA_H
#include <QWidget>
#include <QPainter>
#include <QPixmap>
class paintarea : public QWidget
{
Q_OBJECT
public:
paintarea(QWidget *parent = 0);
void load_image(const QString &fileName);
protected:
void paintEvent(QPaintEvent *event);
QPixmap image;
bool status;
};
#endif // PAINTAREA_H
To copy to clipboard, switch view to plain text mode
paintarea.cpp
#include "paintarea.h"
paintarea
::paintarea (QWidget *parent
) :{
//QPixmap image;
// image = new QPixmap;
status = false ;
}
{
if(status)
{
painter.drawPixmap(0,0,image);
//painter.drawRect(0,0,30,40);
}
}
void paintarea
::load_image(const QString &fileName
) {
image.load(fileName);
status = true ;
}
#include "paintarea.h"
paintarea::paintarea (QWidget *parent) :
QWidget(parent)
{
//QPixmap image;
// image = new QPixmap;
status = false ;
}
void paintarea::paintEvent(QPaintEvent *event)
{
if(status)
{
QPainter painter(this);
painter.drawPixmap(0,0,image);
//painter.drawRect(0,0,30,40);
}
}
void paintarea::load_image(const QString &fileName)
{
image.load(fileName);
status = true ;
}
To copy to clipboard, switch view to plain text mode
Bookmarks