Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to display background when all QTabWidgets are closed
Forum Updated to NodeBB v4.3 + New Features

how to display background when all QTabWidgets are closed

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 187 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Blackzero
    wrote on last edited by
    #1

    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

    Screenshot 2024-08-10 235118.jpg

    JonBJ 1 Reply Last reply
    0
    • B Blackzero

      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

      Screenshot 2024-08-10 235118.jpg

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Blackzero
      Did you try

      QTabWidget
      {
      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.

      B 1 Reply Last reply
      0
      • JonBJ JonB

        @Blackzero
        Did you try

        QTabWidget
        {
        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.

        B Offline
        B Offline
        Blackzero
        wrote on last edited by
        #3

        @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("");
            }
        }
        
        JonBJ 1 Reply Last reply
        0
        • B Blackzero

          @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("");
              }
          }
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Blackzero
          Seems reasonable to me. I don't know why you changed it to do it on QTabWidget::tabCloseRequested rather than QTabWidget::currentChanged or why you use image: rather than background-image: but doubtless these work for you.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved