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. perform layout before window is shown?
Forum Updated to NodeBB v4.3 + New Features

perform layout before window is shown?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 470 Views 2 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.
  • D Offline
    D Offline
    davecotter
    wrote on last edited by
    #1

    I need to find the rectangles of some controls in my window, BEFORE the window is shown.

    but it seems all rectangles have top-left as (0, 0), until i show the window, only THEN do they jump to the proper place.

    my workaround is to briefly show-hide the window, THEN get the rectangles, THEN officially "show" the window.

    so, how do i get the rectangles to update WITHOUT showing the window? here is my function:

    void				CWindow::UpdateLayout(bool via_hide_showB)
    {
    	QWidget*	qWidgetP(GetQtWind());
    
    	CF_ASSERT(qWidgetP);
    	if (qWidgetP) {
    
    		if (via_hide_showB) {
    			QtWindow*		qWindP(dynamic_cast<QtWindow*>(qWidgetP));
    
    			CF_ASSERT(qWindP);
    			if (qWindP) {
    				qWindP->Show(true);
    				qWindP->Show(false);
    				qWindP->i_did_hideshowB = true;
    			}
    		} else {
    			QLayout*	layoutP(qWidgetP->layout());
    
    			CF_ASSERT(layoutP);
    			if (layoutP) {
    				//	these 2 cause the layout to run, so items
    				//	are now at their default sizes
    				layoutP->update();
    				layoutP->activate();
    
    				// qWidgetP->dumpObjectTree();
    			}
    		}
    	}
    }
    

    Note i'd LIKE to take the second block, but IT DOESN'T WORK, so i instead take the first block, which ALWAYS works, but it FLASHES the windows on the screen :(

    Pl45m4P 1 Reply Last reply
    0
    • D Offline
      D Offline
      davecotter
      wrote on last edited by davecotter
      #9
      This post is deleted!
      1 Reply Last reply
      0
      • D davecotter

        I need to find the rectangles of some controls in my window, BEFORE the window is shown.

        but it seems all rectangles have top-left as (0, 0), until i show the window, only THEN do they jump to the proper place.

        my workaround is to briefly show-hide the window, THEN get the rectangles, THEN officially "show" the window.

        so, how do i get the rectangles to update WITHOUT showing the window? here is my function:

        void				CWindow::UpdateLayout(bool via_hide_showB)
        {
        	QWidget*	qWidgetP(GetQtWind());
        
        	CF_ASSERT(qWidgetP);
        	if (qWidgetP) {
        
        		if (via_hide_showB) {
        			QtWindow*		qWindP(dynamic_cast<QtWindow*>(qWidgetP));
        
        			CF_ASSERT(qWindP);
        			if (qWindP) {
        				qWindP->Show(true);
        				qWindP->Show(false);
        				qWindP->i_did_hideshowB = true;
        			}
        		} else {
        			QLayout*	layoutP(qWidgetP->layout());
        
        			CF_ASSERT(layoutP);
        			if (layoutP) {
        				//	these 2 cause the layout to run, so items
        				//	are now at their default sizes
        				layoutP->update();
        				layoutP->activate();
        
        				// qWidgetP->dumpObjectTree();
        			}
        		}
        	}
        }
        

        Note i'd LIKE to take the second block, but IT DOESN'T WORK, so i instead take the first block, which ALWAYS works, but it FLASHES the windows on the screen :(

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #2

        @davecotter

        Use your widgets's showEvent for this.
        When this function is called, the widget is not yet shown but has its actual size/layout (geometry) already.


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        D 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @davecotter

          Use your widgets's showEvent for this.
          When this function is called, the widget is not yet shown but has its actual size/layout (geometry) already.

          D Offline
          D Offline
          davecotter
          wrote on last edited by
          #3

          @Pl45m4 said in perform layout before window is shown?:

          @davecotter

          Use your widgets's showEvent for this.

          how exactly? call it on the layoutP? iterate through every widget and call it on each one? i'm not sure what you mean.

          i'm looking for one call for "make all my widgets know their rectangles", so that after that one call, NOT during an event handler, i can then ask any widget for its rectangle.

          how do i do that?

          Pl45m4P 1 Reply Last reply
          0
          • D davecotter

            @Pl45m4 said in perform layout before window is shown?:

            @davecotter

            Use your widgets's showEvent for this.

            how exactly? call it on the layoutP? iterate through every widget and call it on each one? i'm not sure what you mean.

            i'm looking for one call for "make all my widgets know their rectangles", so that after that one call, NOT during an event handler, i can then ask any widget for its rectangle.

            how do i do that?

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by Pl45m4
            #4

            @davecotter said in perform layout before window is shown?:

            how exactly? call it on the layoutP?

            Like this (in QtWindow class directly, not in CWindow).

            void QtWindow:::showEvent(QShowEvent * event)
            {
            
                // do something with your "rectangles" here
            
                QWidget::showEvent(event);
            }
            

            @davecotter said in perform layout before window is shown?:

            i'm looking for one call for "make all my widgets know their rectangles", so that after that one call, NOT during an event handler, i can then ask any widget for its rectangle.

            Mh... don't know if you can actively force the Qt widget to "show" without showing...
            I know that inside the widgets c'tor the layouts and geometry / sizes are not correct, but during the showEvent they are.
            So if you need to get any actual position or geometry before the widget appears on screen, the showEvent would be the right place.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            0
            • D Offline
              D Offline
              davecotter
              wrote on last edited by
              #5

              no you are not understanding. i do NOT want to show the window first. i want the rectangles updated when NO SHOW EVENT has been sent.
              i'm not asking them to be shown, i'm asking them to update their rectangles.

              Pl45m4P 1 Reply Last reply
              0
              • D Offline
                D Offline
                davecotter
                wrote on last edited by
                #6

                i need the rectangle info from ALL the widgets, BEFORE the WINDOW is shown.
                Maybe i show it offscreen??

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  davecotter
                  wrote on last edited by
                  #7

                  it sounds like you're saying that this sequence is a no-op when the window is hidden?

                  layoutP->update();
                  layoutP->activate();
                  
                  1 Reply Last reply
                  0
                  • D davecotter

                    no you are not understanding. i do NOT want to show the window first. i want the rectangles updated when NO SHOW EVENT has been sent.
                    i'm not asking them to be shown, i'm asking them to update their rectangles.

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by Pl45m4
                    #8

                    @davecotter said in perform layout before window is shown?:

                    no you are not understanding. i do NOT want to show the window first. i want the rectangles updated when NO SHOW EVENT has been sent.

                    Yeah, after re-reading I understand... have edited my post.

                    You want something like this:

                    • https://www.qtcentre.org/threads/13268-make-a-widget-paint-itself-even-thought-it-is-not-shown

                    "Paint the widget" with its actual layout and size, without showing any of it.

                    There is no such function directly in Qt, but it can possibly be achieved with a workaround.
                    (which I unfortunately don't know right now)


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      davecotter
                      wrote on last edited by davecotter
                      #9
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • D davecotter has marked this topic as solved on

                      • Login

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