Results 1 to 20 of 30

Thread: subclass the QLabel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Posts
    36
    Thanks
    30
    Qt products
    Qt4
    Platforms
    Windows

    Default subclass the QLabel

    I want to get the coordinate from Qlabel when I double click on...
    how do I sub class the Qlabel in ui application
    my code looks:
    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. MainWindow::~MainWindow()
    12. {
    13. delete ui;
    14. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit MainWindow(QWidget *parent = 0);
    16. ~MainWindow();
    17.  
    18.  
    19. private:
    20. Ui::MainWindow *ui;
    21. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: subclass the QLabel

    is your question probably about promition if you google it? If I understand well, you want to give extra features to QLabel, than in the first step "promote to" is your friend, you may find more information in the documentation.
    Szilvi

  3. #3
    Join Date
    Mar 2011
    Posts
    36
    Thanks
    30
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: subclass the QLabel

    is your question probably about promition if you google it?
    Is your answer to this thread is promotion??

  4. #4
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: subclass the QLabel

    hi , u can override the mousPressEvent
    Qt Code:
    1. void QLabel::mousePressEvent(QMouseEvent *evt)
    2. {
    3. qDebug()<<"X"<<evt->x()<<"Y"<<evt->y();
    4. }
    To copy to clipboard, switch view to plain text mode 

    hope it helps
    Bala

  5. The following user says thank you to BalaQT for this useful post:

    ready (25th March 2011)

  6. #5
    Join Date
    Mar 2011
    Posts
    36
    Thanks
    30
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: subclass the QLabel

    thanks bala...
    but i am getting confused where should i declare the class to override the mousepressevent..
    is it in mainwindows.h??

  7. #6
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: subclass the QLabel

    put it in mainwindow.cpp

    hope it helps
    Bala

  8. The following user says thank you to BalaQT for this useful post:

    ready (25th March 2011)

  9. #7
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: subclass the QLabel

    Quote Originally Posted by BalaQT View Post
    hi , u can override the mousPressEvent
    Qt Code:
    1. void QLabel::mousePressEvent(QMouseEvent *evt)
    2. {
    3. qDebug()<<"X"<<evt->x()<<"Y"<<evt->y();
    4. }
    To copy to clipboard, switch view to plain text mode 

    hope it helps
    Bala
    Do you really think this will compile and link? No comment!


    @topic:
    The simples way to solve this problem is to install event filter see: QObject::installEventFilter for details.

    Another think you are doing common mistake in asking questions!
    You giving us ready solution of your problem and asking how to make it work.
    First you should explain what you want to achieve then explain how you tried to solve it this problem. I wouldn't be surprised if some would give you a better solution of primary problem.
    Last edited by MarekR22; 25th March 2011 at 08:55.

  10. The following user says thank you to MarekR22 for this useful post:

    ready (25th March 2011)

  11. #8
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: subclass the QLabel

    Do you really think this will compile and link? No comment!
    yes it is compiling. whats wrong?
    have you try in your end?

    bala

  12. The following user says thank you to BalaQT for this useful post:

    ready (25th March 2011)

  13. #9
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: subclass the QLabel

    does it work?

  14. The following user says thank you to MarekR22 for this useful post:

    ready (25th March 2011)

  15. #10
    Join Date
    Mar 2011
    Posts
    36
    Thanks
    30
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: subclass the QLabel

    thanks marek
    the event filter class u mentioned above...
    do I need to declare this class in mainwindow.cpp(of ui class)

  16. #11
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: subclass the QLabel

    I still think that your approach is totally wrong! QLabel is design just to visualize text not for user interaction. What you are try to do in first place?

  17. The following user says thank you to MarekR22 for this useful post:

    ready (25th March 2011)

Similar Threads

  1. Replies: 8
    Last Post: 12th February 2010, 02:41
  2. Replies: 1
    Last Post: 29th September 2009, 19:44
  3. Replies: 1
    Last Post: 2nd August 2008, 15:46
  4. Subclass Pushbutton
    By Smith in forum Newbie
    Replies: 6
    Last Post: 8th December 2007, 12:56
  5. Subclass
    By merry in forum General Programming
    Replies: 2
    Last Post: 1st March 2007, 10:34

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.