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
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QtGui/QMainWindow>
  5. #include <QPushButton>
  6.  
  7. namespace Ui
  8. {
  9. class mainwindow;
  10. }
  11.  
  12. class mainwindow : public QMainWindow
  13. {
  14. Q_OBJECT
  15.  
  16. public:
  17. mainwindow(QWidget *parent = 0);
  18. ~mainwindow();
  19.  
  20. private:
  21. Ui::mainwindow *ui;
  22. QPushButton *button;
  23.  
  24. public slots:
  25. void send_signal();
  26. };
  27.  
  28. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 

mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3.  
  4. mainwindow::mainwindow(QWidget *parent)
  5. : QMainWindow(parent), ui(new Ui::mainwindow)
  6. {
  7. ui->setupUi(this);
  8.  
  9. button = new QPushButton;
  10. button = ui->button;
  11.  
  12. connect (button,SIGNAL (clicked()),this,SLOT (send_signal()));
  13. }
  14.  
  15. mainwindow::~mainwindow()
  16. {
  17. delete ui;
  18. }
  19.  
  20. void mainwindow::send_signal()
  21. {
  22. paint_space->load_image("/home/xxx/picture.jpeg");
  23. }
To copy to clipboard, switch view to plain text mode 

paintarea.h
Qt Code:
  1. #ifndef PAINTAREA_H
  2. #define PAINTAREA_H
  3.  
  4. #include <QWidget>
  5. #include <QPainter>
  6. #include <QPixmap>
  7.  
  8. class paintarea : public QWidget
  9. {
  10. Q_OBJECT
  11. public:
  12. paintarea(QWidget *parent = 0);
  13. void load_image(const QString &fileName);
  14.  
  15. protected:
  16. void paintEvent(QPaintEvent *event);
  17. QPixmap image;
  18. bool status;
  19. };
  20.  
  21. #endif // PAINTAREA_H
To copy to clipboard, switch view to plain text mode 

paintarea.cpp

Qt Code:
  1. #include "paintarea.h"
  2.  
  3. paintarea::paintarea (QWidget *parent) :
  4. QWidget(parent)
  5. {
  6. //QPixmap image;
  7. // image = new QPixmap;
  8. status = false ;
  9. }
  10.  
  11. void paintarea::paintEvent(QPaintEvent *event)
  12. {
  13. if(status)
  14. {
  15. QPainter painter(this);
  16. painter.drawPixmap(0,0,image);
  17. //painter.drawRect(0,0,30,40);
  18.  
  19. }
  20.  
  21. }
  22.  
  23. void paintarea::load_image(const QString &fileName)
  24. {
  25.  
  26. image.load(fileName);
  27. status = true ;
  28.  
  29. }
To copy to clipboard, switch view to plain text mode