qt获取tabwidget中创建pushbutton的点击信号
时间: 2023-08-05 15:02:11 浏览: 110
qt-tabwidget-标题栏tab颜色设置
3星 · 编辑精心推荐
您可以使用以下代码来获取 `QTabWidget` 中创建的 `QPushButton` 的点击信号:
```cpp
// Assuming that you have a QTabWidget object named 'tabWidget'
// and there is a QPushButton object named 'pushButton' in one of the tabs
// Get the widget of the tab containing the QPushButton
QWidget* tabContainingPushButton = tabWidget->widget(indexOfTabContainingPushButton);
// Find the QPushButton object in the widget
QPushButton* pushButton = tabContainingPushButton->findChild<QPushButton*>("pushButton");
// Connect the clicked() signal of the QPushButton to a slot
connect(pushButton, &QPushButton::clicked, this, &MyClass::onPushButtonClicked);
```
Here, `indexOfTabContainingPushButton` is the index of the tab containing the `QPushButton` and `MyClass::onPushButtonClicked` is the slot that will be executed when the `QPushButton` is clicked.
阅读全文