Resizing a widget's non-Qt child window after resize
-
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.
ProudOneAnswered 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?
-
[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.
-
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.
-
[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);@