×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Dec 2010
    Location
    Delhi,INDIA
    Posts
    25

    Post How to declare a function for click button event

    //mainwindow.h
    Code:
    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);
     };
    //mainwindow.cpp
    Code:
    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();
     }
    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...
    Last edited by prajnaranjan.das; 2010-12-24 at 09:08.
    Prajnaranjan Das

    e mail: prajnaranjan.das@gmail.com

  2. #2
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to declare a function for click button event

    Each widget needs its own object instance, but they do not need to be distinct classes, if you can, eg, differentiate their function during construction.

Similar Threads

  1. How to use button click event in carbide c++?
    By nokia.vtrack in forum Symbian
    Replies: 5
    Last Post: 2010-12-12, 14:23
  2. Dynamically adding a mouse click event to button movieclip
    By ranco in forum [Archived] Flash Lite on Nokia Devices
    Replies: 7
    Last Post: 2010-01-05, 21:52
  3. click on button and radio button
    By videoFx in forum [Archived] Flash Lite on Nokia Devices
    Replies: 1
    Last Post: 2009-10-22, 23:29
  4. Replies: 5
    Last Post: 2008-12-08, 08:25
  5. HELP! Hot to declare active function!!
    By joseph.m in forum Symbian
    Replies: 17
    Last Post: 2008-07-17, 03:27

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×