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. To hide all widgets in a grid layout
Forum Updated to NodeBB v4.3 + New Features

To hide all widgets in a grid layout

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.6k 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.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by
    #1

    baf135c7-6c58-438d-a65a-825d2481e927-image.png

    There are several layouts in the grid layout, and there are several widgets in it, so is there a way to access the parent layout and hide all widgets in the sublayout?

    void AA::LayoutVisible(QLayout* layout, bool bShow, int nIndex)
    {
        int ncount = layout->count();
        /*if (layout->count() < nIndex)
            return;*/
    
        /*if (layout->count() == 1)
            return;*/
    
        for (int i = 0; i < layout->count(); i++)
        {
    		QLayoutItem* pItem = layout->itemAt(i);
            if( pItem->widget() )
                pItem->widget()->hide();
        }
    
        //layout->itemAt(nIndex)->widget()->setVisible(bShow);
    }
    
    

    I turned the Gridrayout pointer over to the factor in my way, and there was a null pointer error.

    JonBJ 1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      If it was me I would put the gridlayout in its own widget and setvisible(false) the top level widget instead of trying to traverse the tree and inspect all the gridlayout items. Keep in mind that hiding a widget will probably have consequences on the higher level layout during redraw so your size policies need to be correct.

      1 Reply Last reply
      3
      • I IknowQT

        baf135c7-6c58-438d-a65a-825d2481e927-image.png

        There are several layouts in the grid layout, and there are several widgets in it, so is there a way to access the parent layout and hide all widgets in the sublayout?

        void AA::LayoutVisible(QLayout* layout, bool bShow, int nIndex)
        {
            int ncount = layout->count();
            /*if (layout->count() < nIndex)
                return;*/
        
            /*if (layout->count() == 1)
                return;*/
        
            for (int i = 0; i < layout->count(); i++)
            {
        		QLayoutItem* pItem = layout->itemAt(i);
                if( pItem->widget() )
                    pItem->widget()->hide();
            }
        
            //layout->itemAt(nIndex)->widget()->setVisible(bShow);
        }
        
        

        I turned the Gridrayout pointer over to the factor in my way, and there was a null pointer error.

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

        @IknowQT
        As @Kent-Dorfman says it would seem neater if you hid the whole of a widget containing the layout.

        But if you do want to do it your way:

        I turned the Gridrayout pointer over to the factor in my way, and there was a null pointer error.

        Use a debugger to see where it "crashes". I am wondering:

        		QLayoutItem* pItem = layout->itemAt(i);
                if( pItem->widget() )
        

        I would check for pItem != nullptr.

        1 Reply Last reply
        2

        • Login

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