how to display background when all QTabWidgets are closed
-
wrote on 10 Aug 2024, 16:51 last edited by
-
How to display a background image when all tabs from QTabwidget are closed, for example like Visual studio code when all tabs are closed there is a background, is that possible?
for example like this image when all tabs are closed there is a background image
wrote on 10 Aug 2024, 17:24 last edited by JonB 8 Oct 2024, 17:25@Blackzero
Did you tryQTabWidget { background-image: url(:/img/background.png); }
?
If that does not work (because
QTabWidget
is empty/has no tabs, or you don't want it when there are some tabs) more advanced discussion in https://forum.qt.io/topic/145432/how-to-set-the-qtabwidget-background-image-when-there-is-not-any-widget-page. -
@Blackzero
Did you tryQTabWidget { background-image: url(:/img/background.png); }
?
If that does not work (because
QTabWidget
is empty/has no tabs, or you don't want it when there are some tabs) more advanced discussion in https://forum.qt.io/topic/145432/how-to-set-the-qtabwidget-background-image-when-there-is-not-any-widget-page.wrote on 10 Aug 2024, 21:02 last edited by@JonB I modeled the code of Abderrahmene_Rayenein my own way, so every time I add a new tab I have to clear the setStyleSheet I don't know if this is efficient.
void MainWindow::on_tabWidget_tabCloseRequested(int index) { ui->tabWidget->removeTab(index); if (ui->tabWidget->count() == 0) { ui->tabWidget->setStyleSheet("image: url(:/img/default.png);"); } else { ui->tabWidget->setStyleSheet(""); } }
-
@JonB I modeled the code of Abderrahmene_Rayenein my own way, so every time I add a new tab I have to clear the setStyleSheet I don't know if this is efficient.
void MainWindow::on_tabWidget_tabCloseRequested(int index) { ui->tabWidget->removeTab(index); if (ui->tabWidget->count() == 0) { ui->tabWidget->setStyleSheet("image: url(:/img/default.png);"); } else { ui->tabWidget->setStyleSheet(""); } }
wrote on 11 Aug 2024, 07:16 last edited by@Blackzero
Seems reasonable to me. I don't know why you changed it to do it onQTabWidget::tabCloseRequested
rather thanQTabWidget::currentChanged
or why you useimage:
rather thanbackground-image:
but doubtless these work for you.
1/4