Results 1 to 5 of 5

Thread: QTabWidget currentChanged signal

  1. #1
    Join Date
    Aug 2009
    Posts
    13
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default QTabWidget currentChanged signal

    I have a QTabWidget object named myTabWidget

    If I understand it correctly, currentChanged(int) signal is emitted in 3 cases:
    1. myTabWidget.addTab() is called.
    2. myTabWidget.insertTab() is called.
    3. the user clicks/presses on a different tab bar.

    Is there a way to emit currentChanged signal only for the 3rd case? My tabs are dynamically added/removed throughout the life of the application, and I want to generate a key click sound only if the user changes tab, but not when a new tab is added/inserted.

    I'm using QtEmbedded 4.5.3.

    Thanks in advance for any suggestion

  2. #2
    Join Date
    Sep 2009
    Location
    Finland
    Posts
    63
    Thanks
    1
    Thanked 22 Times in 19 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QTabWidget currentChanged signal

    I use desktop environment (Ubuntu / Qt 5.4.2) and at least in this environment the currentChanged is only emitted when the page is actually changed. So if I create a new tab either by using insertTab or addTab the tab does not change and because of that the signal is not emitted.

    Usually after tab is created it is activated by calling setCurrentIndex method for the tab index that was created i.e.

    Qt Code:
    1. int index = tab->addTab(page, QString("label"));
    2. tab->setCurrentIndex(index);
    To copy to clipboard, switch view to plain text mode 

    So I would say that the currentChanged is only emitted in the 3rd case, not in 1st and 2nd cases.

  3. #3
    Join Date
    Aug 2009
    Posts
    13
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QTabWidget currentChanged signal

    My QtEmbedded 4.5.3 seems to call setCurrentIndex inside addTab and insertTab functions
    Is there some way for me to work around this? I'm trying to overwrite mousePressEvent but haven't come up with any solution yet

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTabWidget currentChanged signal

    use QObject::blockSignals.
    e.g.
    Qt Code:
    1. ...
    2. const bool isBlocked = myTabWidget->blockSignals(true);
    3. //insertion or removal pages
    4. myTabWidget->blockSignals(isBlocked);
    5. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    vkincaid (9th December 2009)

  6. #5
    Join Date
    Aug 2009
    Posts
    13
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QTabWidget currentChanged signal

    Thank you spirit! That works like a charm!

Similar Threads

  1. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  3. Replies: 1
    Last Post: 29th April 2008, 12:12
  4. QTabWidget SIGNAL currentChanged()
    By campana in forum Qt Programming
    Replies: 3
    Last Post: 28th February 2006, 10:09

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.