how to display background when all QTabWidgets are closed
-
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
-
@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. -
@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(""); } }
-
@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.