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. What happens to widgets added to QTabWidget?
Qt 6.11 is out! See what's new in the release blog

What happens to widgets added to QTabWidget?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 902 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.
  • D Offline
    D Offline
    django.Reinhard
    wrote on last edited by
    #1

    Hi,

    I had lots of widgets in a stacked layout and wanted to group some of them in a QTabWidget but something very strange happens:

    This is the page in stacked layout:

    Settings_stacked.jpg

    and this is the same widget (unchanged!) added to a QTabWidget.
    Settings_tabbed.jpg
    Font and colors are read from QSettings and applied by QLabel::setStyleSheet(...)

    Every button is connected to functions that will raise a dialog to change color/font - but when the widget is part of QTabWidget, no button works.

    some code excerpts - first the stacked page:

      page = new PreferencesEditor(":/src/UI/Settings.ui", mainView);
      mainView->addPage(page);
      ui->menuMain->addAction(page->viewAction());
    
      SettingsNotebook* nb = new SettingsNotebook(this);
    
      nb->addPage(new ToolManager(conn, nb));
      nb->addPage(new FixtureManager(Core().axisMask(), nb));
    //  nb->addPage(new PreferencesEditor(":/src/UI/Settings.ui", nb));
      mainView->addPage(nb);
      ui->menuMain->addAction(nb->viewAction());
    

    ... and here the tabbed page:

    //  page = new PreferencesEditor(":/src/UI/Settings.ui", mainView);
    //  mainView->addPage(page);
    //  ui->menuMain->addAction(page->viewAction());
    
      SettingsNotebook* nb = new SettingsNotebook(this);
    
      nb->addPage(new ToolManager(conn, nb));
      nb->addPage(new FixtureManager(Core().axisMask(), nb));
      nb->addPage(new PreferencesEditor(":/src/UI/Settings.ui", nb));
      mainView->addPage(nb);
      ui->menuMain->addAction(nb->viewAction());
    

    addPage is just a wrapper around addTab which uses the objectName as Name for the tab.

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You set a stylesheet to your QTabWidget which is also applied to the children. Fix your stylesheet so it's only applied to your QTabWidget.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • D Offline
        D Offline
        django.Reinhard
        wrote on last edited by
        #3

        Hi,

        maybe I don't understand you.

        At the moment I don't care for the QTabWidget at all.
        The page with the buttons and labels is a separate class and this class applies stylesheets to the labels.

        beside the stylesheet issue - I don't understand, why the button connections don't work any more.

        I added another widget, which is a master/detail widget with QTreeView and QTableView - there the model/view connection don't work when the widget is added to the QTabWidget.

        I guess I have a big misunderstanding of QTabWidget.

        1 Reply Last reply
        0
        • D django.Reinhard

          Hi,

          I had lots of widgets in a stacked layout and wanted to group some of them in a QTabWidget but something very strange happens:

          This is the page in stacked layout:

          Settings_stacked.jpg

          and this is the same widget (unchanged!) added to a QTabWidget.
          Settings_tabbed.jpg
          Font and colors are read from QSettings and applied by QLabel::setStyleSheet(...)

          Every button is connected to functions that will raise a dialog to change color/font - but when the widget is part of QTabWidget, no button works.

          some code excerpts - first the stacked page:

            page = new PreferencesEditor(":/src/UI/Settings.ui", mainView);
            mainView->addPage(page);
            ui->menuMain->addAction(page->viewAction());
          
            SettingsNotebook* nb = new SettingsNotebook(this);
          
            nb->addPage(new ToolManager(conn, nb));
            nb->addPage(new FixtureManager(Core().axisMask(), nb));
          //  nb->addPage(new PreferencesEditor(":/src/UI/Settings.ui", nb));
            mainView->addPage(nb);
            ui->menuMain->addAction(nb->viewAction());
          

          ... and here the tabbed page:

          //  page = new PreferencesEditor(":/src/UI/Settings.ui", mainView);
          //  mainView->addPage(page);
          //  ui->menuMain->addAction(page->viewAction());
          
            SettingsNotebook* nb = new SettingsNotebook(this);
          
            nb->addPage(new ToolManager(conn, nb));
            nb->addPage(new FixtureManager(Core().axisMask(), nb));
            nb->addPage(new PreferencesEditor(":/src/UI/Settings.ui", nb));
            mainView->addPage(nb);
            ui->menuMain->addAction(nb->viewAction());
          

          addPage is just a wrapper around addTab which uses the objectName as Name for the tab.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @django-Reinhard said in What happens to widgets added to QTabWidget?:

          Every button is connected to functions that will raise a dialog to change color/font - but when the widget is part of QTabWidget, no button works.

          Where do you do any of these connect()s?

          1 Reply Last reply
          1
          • D Offline
            D Offline
            django.Reinhard
            wrote on last edited by
            #5

            Hi,

            thank you for your attention and support!
            You're a real professional!
            The right question.

            It took me a while to get it, but - of cause - you where right.
            I'm getting old.
            I forgot the second purpose of DynWidget ancestors - late initialization. So it was a typical PEBCAK.

            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