PDA

View Full Version : QTabWidget currentChanged signal



vkincaid
8th December 2009, 16:05
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 :)

tsp
8th December 2009, 17:01
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.


int index = tab->addTab(page, QString("label"));
tab->setCurrentIndex(index);


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

vkincaid
8th December 2009, 22:05
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 :(

spirit
9th December 2009, 06:25
use QObject::blockSignals.
e.g.


...
const bool isBlocked = myTabWidget->blockSignals(true);
//insertion or removal pages
myTabWidget->blockSignals(isBlocked);
...

vkincaid
9th December 2009, 18:07
Thank you spirit! That works like a charm!