如何聚焦新标签?

发布于 2024-10-08 11:30:20 字数 96 浏览 0 评论 0原文

我可以使用添加新选项卡 qtabwidget->addTab(newtab, title);

但是否可以专注于此 我的代码中的选项卡?

谢谢

I was able to add a new tab using
qtabwidget->addTab ( newtab, title );

But is it possible to focus on this
tab in my code?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凡间太子 2024-10-15 11:30:20

“setCurrentWidget”或“setCurrentIndex”即可完成这项工作。

您可以使用指向添加的小部件的指针或数字索引。

请参阅:

http://doc.qt.io/qt-5/qtabwidget.html #setCurrentWidget

http://doc.qt.io/qt -5/qtabwidget.html#currentIndex-prop

例如,如果您有一个带有 3 个选项卡的选项卡小部件,您可以像这样关注第二个选项卡:

ui->tabWidget->setCurrentIndex(1);

如果您只想使用指向您的小部件的指针 ( QWidget 类型的 MyWidget) 那么这里是另一个例子:

MyWidget* pointerToMyWidgetInTab = new MyWidget();
ui->tabWidget->addTab(pointerToMyWidgetInTab,"Tab2")
ui->tabWidget->setCurrentWidget(pointerToMyWidgetInTab2);

'setCurrentWidget' or 'setCurrentIndex' will do the job.

You can use either the pointer to the added widget or a numeric index.

See:

http://doc.qt.io/qt-5/qtabwidget.html#setCurrentWidget

http://doc.qt.io/qt-5/qtabwidget.html#currentIndex-prop

For example, if you have a tab widget with say 3 tabs, you can focus on the 2nd tab like this:

ui->tabWidget->setCurrentIndex(1);

If you just want to use the pointer to your widget (MyWidget of type QWidget) then here is another example:

MyWidget* pointerToMyWidgetInTab = new MyWidget();
ui->tabWidget->addTab(pointerToMyWidgetInTab,"Tab2")
ui->tabWidget->setCurrentWidget(pointerToMyWidgetInTab2);
两仪 2024-10-15 11:30:20

计算选项卡总数并设置最后一个:

ui->tabWidget->setCurrentIndex(ui->tabWidget->count()-1);

Count the total number of tabs and set the last one:

ui->tabWidget->setCurrentIndex(ui->tabWidget->count()-1);
季末如歌 2024-10-15 11:30:20

.h.cpp

private slots:
void setFocusAddedTab();
void on_addTabButton(); //Add Button

void MainWindow::setFocusAddedTab() {
int x = ui->tabWidget->currentIndex()+1;
ui->tabWidget->setCurrentIndex(x)
   }

void MainWindow::on_addTabButton() {
ui->tabWidget->addTab(...,...);
setFocusAddedTab();
}

.h

private slots:
void setFocusAddedTab();
void on_addTabButton(); //Add Button

.cpp

void MainWindow::setFocusAddedTab() {
int x = ui->tabWidget->currentIndex()+1;
ui->tabWidget->setCurrentIndex(x)
   }

void MainWindow::on_addTabButton() {
ui->tabWidget->addTab(...,...);
setFocusAddedTab();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文