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. QTabWidget hides a child widget and cannot show it again (Qt 5.12.2, mingw64, Windows 7)
Forum Updated to NodeBB v4.3 + New Features

QTabWidget hides a child widget and cannot show it again (Qt 5.12.2, mingw64, Windows 7)

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 412 Views 1 Watching
  • 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.
  • E Offline
    E Offline
    Ejok88
    wrote on last edited by Ejok88
    #1

    Qt 5.12.2, mingw64, Windows 7
    I need to create a tab with two widgets: custom widget and a button. I did:

        auto vbox = new QVBoxLayout;
        vbox->addWidget(customWidget);
        auto pb = new QPushButton("my button");
        vbox->addWidget(pb);
        vbox->addStretch();
        auto w = new QWidget();
        w->setLayout(vbox);
        tw_main = new QTabWidget;
        tw_main->addTab(w, "my tab");
    

    And the first time there are no problems. And "w" widget is shown all. But when I close the tw_main widget and then open it again, there is only a button in "my tab".
    When I debug this behavior, I find out that the customWidget is not shown again (file qwidget.cpp, in func showChildren(bool)) because it has the Qt::WA_WState_Hidden attribute.
    If I insert the customWidget without the proxy widget w, I get normal behavior.

    Now I cope with this problem by next code:

    void MyMainForm::showEvent(QShowEvent *ev)
    {
        if (customWidget)
        {
            customWidget->setVisible(true);
        }
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What version of Qt ?
      What OS ?
      Can you provide a complete minimal example that shows that behavior ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by JoeCFD
        #3

        w is not a child of tw_main or customWidget. Therefore it is not displayed when tw_main->setVisible( true ), right? make customWidget to be w's parent. Try it again.

        E 1 Reply Last reply
        0
        • JoeCFDJ JoeCFD

          w is not a child of tw_main or customWidget. Therefore it is not displayed when tw_main->setVisible( true ), right? make customWidget to be w's parent. Try it again.

          E Offline
          E Offline
          Ejok88
          wrote on last edited by Ejok88
          #4

          @JoeCFD I read about addTab function: "Ownership of page is passed on to the QTabWidget." Why do you think that w is not a child of tw_main? And I read about w->setLayout(): "The QWidget will take ownership of layout." Then I read about vbox->addWidget: "When you use a layout, you do not need to pass a parent when constructing the child widgets. The layout will automatically reparent the widgets (using QWidget::setParent()) so that they are children of the widget on which the layout is installed." So tw_main owns w and w owns customWidget. (And I saw the customWidget in the child list of w in the debug mode)

          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Please check with a more recent Qt version (5.12.8 will be enought if you can't update to 5.15). I think there was a bug around not showing dialogs after the first show somewhere in 5.12.x but don't know if this also affected QTabWidgets. Maybe also search the bugtracker.

            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
            0

            • Login

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