我的 QTabWidget 实现没有检测到它的tabCloseRequested()
和currentChanged()
信号。
TileSheetManager::TileSheetManager(QWidget *parent)
: QTabWidget(parent)
{
int w = WIDTH;
int h = HEIGHT;
this->setMinimumSize(w, h);
this->setMaximumSize(w, h);
setTabsClosable(true);
setTabShape(QTabWidget::Rounded);
connect(this, SIGNAL(tabCloseRequested(int index)), this, SLOT(closeTileWidget(int index)));
connect(this, SIGNAL(currentChanged(int index)), this, SLOT(tabChanged(int index)));
}
qDebug()
对我不起作用,所以我QMessageBox
为此使用了 a 。
void TileSheetManager::closeTileWidget(int index)
{
QMessageBox msgBox;
msgBox.setText("Tab " + QString::number(index) + " removed!");
msgBox.exec();
TileWidget *t = (TileWidget *) widget(index) ;
t->deleteLater();
removeTab(index);
}
void TileSheetManager::tabChanged(int index)
{
QMessageBox msgBox;
msgBox.setText("Tab was Changed!");
msgBox.exec();
TileWidget *t;
for(int i = 0; i < count(); i++)
{
t = (TileWidget *) widget(i) ;
t->resetSetBrush();
}
}
选项卡没有关闭,选定的画笔没有被重置,我没有收到任何消息,所以我得出的结论是信号没有被拾取。这很奇怪,因为我在以前的项目中使用了类似的代码,在这种情况下它起作用了。