Results 1 to 9 of 9

Thread: How to declare a function for click button event

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2010
    Posts
    34
    Qt products
    Qt4
    Platforms
    Windows

    Post How to declare a function for click button event

    //mainwindow.h
    Qt Code:
    1. class ButtonLayout : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. ButtonLayout(QWidget *parent = 0);
    7.  
    8. public slots:
    9. void openImage();
    10.  
    11. };
    12.  
    13. class ImageViewer : public QWidget
    14. {
    15. Q_OBJECT
    16.  
    17. public:
    18. ImageViewer(QWidget *parent = 0);
    19. };
    To copy to clipboard, switch view to plain text mode 
    //mainwindow.cpp
    Qt Code:
    1. ButtonLayout::ButtonLayout(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. QPushButton *btn1 = new QPushButton("IMAGE");
    5.  
    6. connect(btn1,SIGNAL(clicked()),this,SLOT(openImage()));
    7.  
    8. QVBoxLayout *layout = new QVBoxLayout;
    9. layout->addWidget(btn1);
    10. setLayout(layout);
    11. }
    12.  
    13. ImageViewer::ImageViewer(QWidget *parent):QWidget(parent)
    14. {
    15. QLabel *lblImage = new QLabel;
    16. QPixmap pixmap(QPixmap::fromImage(QImage(":/images/Resource/photo.JPG")));
    17. lblImage->setPixmap(pixmap);
    18.  
    19.  
    20. QVBoxLayout *layout = new QVBoxLayout;
    21. layout->addWidget(lblImage);
    22. setLayout(layout);
    23. }
    24.  
    25. void ButtonLayout::openImage()
    26. {
    27. ImageViewer *viewer = new ImageViewer;
    28. viewer->show();
    29. }
    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...
    Last edited by prajnaranjan.das; 24th December 2010 at 09:36.
    Regards:

    Prajnaranjan Das
    e mail: prajnaranjan.das@gmail.com

Similar Threads

  1. How to declare SLOT as a parameter to member function?
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2018, 01:41
  2. Replies: 4
    Last Post: 27th November 2009, 14:00
  3. Replies: 4
    Last Post: 21st March 2009, 14:51
  4. Replies: 2
    Last Post: 12th January 2009, 00:24
  5. Why do i need to declare a function as a slot?
    By cbarmpar in forum Qt Programming
    Replies: 2
    Last Post: 31st August 2008, 21:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.