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. Resizing a widget's non-Qt child window after resize
Forum Updated to NodeBB v4.3 + New Features

Resizing a widget's non-Qt child window after resize

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 4.1k 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.
  • P Offline
    P Offline
    ProudOne
    wrote on last edited by
    #1

    I'm a beginner both in C++ and Qt 4.8.0, so this is probably way past what I'm capable of.
    For a University project, we're starting up Qt with another program and then setting one of Qt's Widgets as the parent to the window of the other program using SetParent(). This all works fantastically, yet whenever the widget is resized, the child window stays the same size and thus its' content is partially invisible.
    I tried fixing that using this function:

    @void MainGUI::slot_resizeEvent() {
    int tmpW = (int) containerWidget->width();
    int tmpH = (int) containerWidget->height();
    SetWindowPos(childWindow, 0, 0, 0, tmpW, tmpH, SWP_NOMOVE);
    InvalidateRect(childWindow, 0, true);
    UpdateWindow(childWindow);
    }@

    I also tried:

    @void MainGUI::slot_resizeEvent() {
    int tmpW = (int) containerWidget->width();
    int tmpH = (int) containerWidget->height();
    MoveWindow(childWindow, 0, 0, containerWidget->width(), containerWidget->height(), true);
    InvalidateRect(childWindow, 0, true);
    UpdateWindow(childWindow);
    }@

    Needless to say; Neither actually resizes the childWindow, nor does the compiler give me any errors.

    Thanks for your time.
    ProudOne

    Answered by Andre: For the moment, the method's connected to a simple GUI-Button for debugging, but I'm planning to hook the working one to the repaint-event of the widget. Would that be the right course of action or is there a resize-signal?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Well, if Qt is embedded in the other application, then I think that it is up to the other application to resize the Qt widget. For Qt widgets, there is the resizeEvent that you can reimplement, but I don't think it is of any use in this case.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        ProudOne
        wrote on last edited by
        #3

        [quote author="Andre" date="1330933802"]Well, if Qt is embedded in the other application, then I think that it is up to the other application to resize the Qt widget. For Qt widgets, there is the resizeEvent that you can reimplement, but I don't think it is of any use in this case. [/quote]

        Thanks for the answer, but the external application is the child of the Qt-Widget.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          In that case, just reimplement the QWidget::resizeEvent(QResizeEvent * event ) method in your own widget. In that method, you can manually resize the non-Qt child widget/window.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            ProudOne
            wrote on last edited by
            #5

            Thank you very much, that already helped a lot, now I'm getting my debug message (I'm writing the new size of the widget into a program log) when resizing the widget, but the childWindow still refuses to snap to its new size. Any ideas about that one? It's doing it properly when both programs are started initially.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              No idea, especially because you're not showing any of the relevant code of how you even embed the external widget in your Qt application. Show the relevant portions of the code, and perhaps somebody here can help you.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                ProudOne
                wrote on last edited by
                #7

                [quote author="Andre" date="1330962444"]No idea, especially because you're not showing any of the relevant code of how you even embed the external widget in your Qt application. Show the relevant portions of the code, and perhaps somebody here can help you.[/quote]

                Sorry, I thought mentioning SetParent() wouldn't leave much to speculation.

                Here's how I start the child program and hook up the two windows.

                @// I omitted the ShellExecuteInfo-block here

                ShellExecuteEx(&ShExecInfo);

                HWND childWindow = NULL;
                uwid = ui.externalDock;
                uwid->setAttribute(Qt::WA_NativeWindow);
                WId activeWidget = uwid->effectiveWinId();

                //Try finding the child window up to ten times
                int i, nTries = 10;

                for (i = 0; childWindow == NULL && i < nTries; i++)
                {
                childWindow = FindWindowA("ChildWndClass", "ChildName");
                Sleep(200);

                // Get a handle to the Qt widget serving as the parent window
                if (activeWidget == NULL || activeWidget == 0 )
                {
                activeWidget = uwid->effectiveWinId();
                }
                }
                SetWindowLong(childWindow, GWL_STYLE, WS_VISIBLE);
                MoveWindow(childWindow, 0, 0, uwid->width(), uwid->height(), true);

                if (childWindow==NULL)

                {
                emit log_message("ERROR – could not find Qt parent window.");
                return;
                }
                SetParent(childWindow, activeWidget);@

                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