Results 1 to 3 of 3

Thread: How to use focusInEvent method of QWidget by inheriting QTabWidget?

  1. #1
    Join Date
    Jun 2015
    Posts
    109
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default How to use focusInEvent method of QWidget by inheriting QTabWidget?

    Hello,

    I'm trying as shown below,
    We already have this,
    Qt Code:
    1. class Q_WIDGETS_EXPORT QWidget : public QObject, public QPaintDevice
    2. {
    3. //Standard Class
    4. protected:
    5. virtual void focusInEvent(QFocusEvent *event);
    6. virtual void focusOutEvent(QFocusEvent *event);
    7. }
    8. class Q_WIDGETS_EXPORT QTabWidget : public QWidget
    9. {
    10. //Standard Class
    11. }
    To copy to clipboard, switch view to plain text mode 

    Now below, I'm trying to access virtual methods from QWidget, but I'm unable to do that, may be I'm missing some simple basics behind it.
    Qt Code:
    1. class MyWidget : public QTabWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. virtual void focusInEvent(QFocusEvent *event);
    6. virtual void focusOutEvent(QFocusEvent *event);
    7. }
    8. void MyWidget::focusInEvent(QFocusEvent *event)
    9. {
    10. qDebug()<<"focusInEvent";
    11.  
    12. QWidget::focusInEvent(event);
    13. }
    14.  
    15. void MyWidget::focusOutEvent(QFocusEvent *event)
    16. {
    17. qDebug()<<"focusOutEvent";
    18. QWidget::focusOutEvent(event);
    19. }
    To copy to clipboard, switch view to plain text mode 

    I can access virtual methods from QTabWidget but not from QWidget, please give me suggestions on what I'm mistaking here?
    Or its protected, that why I'm unable to access it, is there any way to access such protected methods?
    Thanks
    Last edited by npatil15; 10th December 2019 at 06:04.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to use focusInEvent method of QWidget by inheriting QTabWidget?

    Hi, what happens? I would say that your code should work, although I would call QTabWidget::focusInEvent() instead of QWidget::focusInEvent(). Your code skips the QTabWidget, which might not be what you want.

    Ginsengelf

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to use focusInEvent method of QWidget by inheriting QTabWidget?

    I don't understand the point of making these virtual protected methods public in a derived class. It isn't like you can manually call them from some other class - they are called from within Qt when focus enters or leaves the widget. If you want to implement some custom behavior for these events, then you can either derive from QTabWidget (and leave the methods protected) or use QTabWidget itself and install an event handler on the instance.

    I agree with Ginsengelf - if your base class is QTabWidget, then you should be calling those event handlers and not the ones for QWidget.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QTabWidget or QWidget signals
    By mastupristi in forum Qt Programming
    Replies: 2
    Last Post: 8th November 2016, 18:30
  2. How to get the size of a QWidget in QTabWidget
    By xiangxw in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2011, 01:45
  3. Replies: 3
    Last Post: 19th January 2011, 20:43
  4. Replies: 0
    Last Post: 30th March 2010, 15:49
  5. QWidget::testWFlags() - method in Qt 4?
    By Amanda in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2006, 08:08

Tags for this Thread

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.