[Qt-interest] Catch QTabPane change event before change
David Boosalis
david.boosalis at gmail.com
Tue Oct 5 10:53:35 CEST 2010
if you subclass the widgets that go into the tab widget you can capture the
QWidget::showEvent(QShowEvent *)
before the tabChange signal gets called. Example follows:
MyLabel::MyLabel(QString name, QWidget *parent):QLabel(name,parent)
{
}
void MyLabel::showEvent(QShowEvent *se)
{
qDebug() << "Show Me " << QLabel::text();
QLabel::showEvent(se);
}
TabChangeExample::TabChangeExample(QWidget *parent)
: QWidget(parent)
{
tabW = new QTabWidget(this);
connect(tabW,SIGNAL(currentChanged(int)),this,SLOT(tabChangedSlot(int)));
myLabel1 = new MyLabel("ONE",tabW);
myLabel2 = new MyLabel("Two",tabW);
tabW->insertTab(0,myLabel1,"Alpha");
tabW->insertTab(2,myLabel2,"Beta");
QHBoxLayout *hbox = new QHBoxLayout(this);
setLayout(hbox);
hbox->addWidget(tabW);
}
TabChangeExample::~TabChangeExample()
{
}
void TabChangeExample::tabChangedSlot(int i)
{
qDebug() << "Tab Changed:" << i;
}
When I run this code, the output is as follows:
Show Me "ONE"
Tab Changed: 0.
in the showEvent() you could probable do things to change before you show
it, or in this case before QLabel::showEvent() gets called.
On Mon, Oct 4, 2010 at 11:37 PM, Matthias Paul <slayer81 at gmx.de> wrote:
>
>> Hello!
>>
>> I use a QTabPane with three 3 panes. Each panel has some QTextFields for
>> user inputs.
>> If the user changes input on pane 1 and then tries to switch to pane 2 or
>> 3, I'd like to display a message that asks the user whether he wants to save
>> his input or not.
>>
>> There's a signal "currentChange(int)" in QTabPane, which triggers after
>> the tab has actually changed. Is there a way to catch a signal _before_ the
>> change is going to happen, so I am able to overrule the change?
>>
>>
>> Thank you,
>> Paule
>> --
>> GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit
>> gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101005/e7d6c14e/attachment.html
More information about the Qt-interest-old
mailing list