Results 1 to 10 of 10

Thread: Subclassed qlistwidget event handling problem

  1. #1
    Join Date
    Feb 2010
    Location
    Russia, Omsk
    Posts
    28
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Subclassed qlistwidget event handling problem

    Quote Originally Posted by Annihilator View Post
    Handlers for mouseMoveEvent, keyPressEvent and paintEvent work but for itemPressed, currentRowChanged, currentItemChanged do not. What`s the problem?
    It's because they are signals and not event handlers! Use QObject::connect() to connect them to a local slot.

  3. #3
    Join Date
    Feb 2010
    Location
    Russia, Omsk
    Posts
    28
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Subclassed qlistwidget event handling problem

    I`ve made
    Qt Code:
    1. connect(this, SIGNAL(itemPressed( QListWidgetItem * item )), SLOT(itemPressed_s ( QListWidgetItem * item )));
    To copy to clipboard, switch view to plain text mode 
    defined slot in header file of mywidget
    Qt Code:
    1. void itemPressed_s ( QListWidgetItem * item );
    To copy to clipboard, switch view to plain text mode 
    but still does not work

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Subclassed qlistwidget event handling problem

    where is the connect statement and please can you show us your full header file. Have you also recompiled your project, used the Q_OBJECT makro...

    Your syntax is fine, so it normally should work.

  5. #5
    Join Date
    Feb 2010
    Location
    Russia, Omsk
    Posts
    28
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Subclassed qlistwidget event handling problem

    Qt Code:
    1. class CustomListWidget : public QListWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit CustomListWidget(QWidget *parent = 0);
    6.  
    7. signals:
    8.  
    9. //void currentItemChanged ( QListWidgetItem * current, QListWidgetItem * previous );
    10. //void itemPressed ( QListWidgetItem * item );
    11. public slots:
    12. void itemPressed_s ( QListWidgetItem * item );
    13. void currentItemChanged_s ( QListWidgetItem * current, QListWidgetItem * previous );
    14. public:
    15. int currentItemIndex;
    16. QListWidgetItem *currentItem;
    17.  
    18. protected:
    19. void paintEvent(QPaintEvent *pe);
    20. void keyPressEvent(QKeyEvent *event);
    21. void mouseMoveEvent(QMouseEvent *event);
    22. };
    To copy to clipboard, switch view to plain text mode 

    I`ve tried to make connection in CustomListWidget constructor (my last post)

    Also I`ve tried in MainWindow constructore like
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. QObject::connect(ui->listWidget, SIGNAL(itemPressed( QListWidgetItem * item )), SLOT(itemPressed_s ( QListWidgetItem * item )));
    7. }
    To copy to clipboard, switch view to plain text mode 
    but nothing happened. I always rebuild my project.

    p.s.
    here is my slot

    Qt Code:
    1. void CustomListWidget::itemPressed_s ( QListWidgetItem * item )
    2. {
    3.  
    4. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Subclassed qlistwidget event handling problem

    Hi,

    make the connection in the c-tor of your CustomListWidget. And what exactly is not working for you? try
    Qt Code:
    1. void CustomListWidget::itemPressed_s ( QListWidgetItem * item )
    2. {
    3. qWarning() << "slot reached: itemPressed_s";
    4. }
    To copy to clipboard, switch view to plain text mode 

    Did you see the output?


    And as a note: in your mainwindow it has to be:
    Qt Code:
    1. QObject::connect(ui->listWidget, SIGNAL(itemPressed( QListWidgetItem * item )), ui->listWidget, SLOT(itemPressed_s ( QListWidgetItem * item )));
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassed qlistwidget event handling problem

    You dont have to mention the type name in signal and slot,,,only the type.
    This
    Qt Code:
    1. QObject::connect(ui->listWidget, SIGNAL(itemPressed( QListWidgetItem * item )), SLOT(itemPressed_s ( QListWidgetItem * item )));
    To copy to clipboard, switch view to plain text mode 

    should be -
    Qt Code:
    1. QObject::connect(ui->listWidget, SIGNAL(itemPressed( QListWidgetItem * )), SLOT(itemPressed_s ( QListWidgetItem * )));
    To copy to clipboard, switch view to plain text mode 
    Try and see if it works

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

    Annihilator (13th February 2010)

  9. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Subclassed qlistwidget event handling problem

    @aamer4u: Damn, you are right! need to go to an optician

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

    Annihilator (13th February 2010)

  11. #9
    Join Date
    Feb 2010
    Location
    Russia, Omsk
    Posts
    28
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Subclassed qlistwidget event handling problem

    Ooops. that's it! Thanks, aamer4yu!

  12. #10
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassed qlistwidget event handling problem

    @Lykurg... it happens sometimes to me too....the tiniest details are skipped by mind ,, u are not alone !!

    @Annhilator.. welcome :-)

Similar Threads

  1. QThread event handling and QWaitCondition
    By mattc in forum Qt Programming
    Replies: 2
    Last Post: 21st August 2009, 13:00
  2. Handling mouse over event for QListWidget
    By Abc in forum Qt Programming
    Replies: 2
    Last Post: 22nd July 2008, 18:32
  3. SplashScreen and Event handling???
    By Nithya in forum Qt Programming
    Replies: 4
    Last Post: 25th April 2008, 07:05
  4. event handling...
    By xyzt in forum Qt Programming
    Replies: 1
    Last Post: 25th March 2008, 07:16
  5. Event handling problem
    By Mel Seyle in forum Qt Programming
    Replies: 2
    Last Post: 23rd August 2007, 04:15

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.