Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behavior in the execution of WinId() in Qt5.13.0 #938

Closed
akiyosi opened this issue Aug 24, 2019 · 10 comments
Closed

Strange behavior in the execution of WinId() in Qt5.13.0 #938

akiyosi opened this issue Aug 24, 2019 · 10 comments

Comments

@akiyosi
Copy link

akiyosi commented Aug 24, 2019

Hi,
I founded the strange behavior about WinId().

Problem

The size that can be obtained from FrameGeometry() varies depending on whether or not WinId() is executed. It seems to exclude the frame size.
This problem did not occur in the bindings with Qt 5.12.
MacOS does not have this problem. Windows only.

Steps to reproduce the problem

Run the following minimal reproduction program on Windows.

package main

import (
	"fmt"

	"github.com/therecipe/qt/widgets"
	"github.com/therecipe/qt/core"
)


func main() {
	app := widgets.NewQApplication(0, nil)

	m := widgets.NewQMainWindow(nil, 0)
	m.WinId()   // this line has the probrem. why ??
	w := widgets.NewQWidget(m, 0)
	l := widgets.NewQVBoxLayout()
	w.SetLayout(l)
	m.SetCentralWidget(w)
	
	m.SetWindowFlag(core.Qt__Window, true)
	m.SetWindowFlag(core.Qt__FramelessWindowHint, true)

	m.InstallEventFilter(m)
	m.ConnectEventFilter(func(watched *core.QObject, event *core.QEvent) bool {
		switch event.Type() {
		case core.QEvent__HoverMove:
			width := m.FrameGeometry().Width()
			height := m.FrameGeometry().Height()
			fmt.Println("debug::hoverMove1:", width, height)
			fmt.Println("debug::hoverMove2:", m.MinimumWidth(), m.MinimumHeight())
		}

		return w.EventFilter(watched, event)
	})

	m.SetMinimumSize2(400, 300)

	label := widgets.NewQLabel(nil, 0)
	label.SetStyleSheet(" * { color: #111; }")
	label.SetText(`example`)

	l.AddWidget(label, 0, 0)

	m.Show()
	w.SetFocus2()
	app.Exec()
}

You can get the following.

// Cases where WinId() is executed
debug::hoverMove1: 378 289
debug::hoverMove2: 400 300

// Cases where WinId() is not executed
debug::hoverMove1: 400 300
debug::hoverMove2: 400 300
@therecipe
Copy link
Owner

therecipe commented Aug 24, 2019

Hey

I tried to reproduce it, but I always get:

debug::hoverMove1: 400 300
debug::hoverMove2: 400 300

with or without using WinId

I did use the windows_64_static docker image to build your example, and did test it on Win7.
The windows_64_static image should also contain Qt 5.13 IIRC.

Which Qt version do you use? The official Qt version? Or the "Fast track" version?

edit: also does using AdjustSize() make any difference?

@akiyosi
Copy link
Author

akiyosi commented Aug 25, 2019

thx.

I did use the windows_64_static docker image to build your example, and did test it on Win7.

I'm testing the probrem on Wondows 10.
By the way, I used WSL (C:\Windows\System32\bash.exe) to get the stdout of the program.
How can I get the standard output on Windows 7 ?
(I have confirmed that the program has this problem even if it does not run on WSL.)

Which Qt version do you use? The official Qt version? Or the "Fast track" version?

I used the official Qt on both MacOS and Linux and built using the latest windows_64_static docker image on MacOS and Linux.

edit: also does using AdjustSize() make any difference?

I will check, but maybe no difference. because I confirmed that executing MinimumWidth() would give me correct size.

@therecipe
Copy link
Owner

I was able to reproduce it on Win10 with the same file that did work correctly on Win7.
So I guess it's a Qt (5.13?) issue.

You can enable the standard output by using QT_DEBUG_CONSOLE=true
For example when using the docker deployment:
QT_DEBUG_CONSOLE=true qtdeploy -docker build windows_64_static
But it also works when you develop/deploy on windows itself.

@akiyosi
Copy link
Author

akiyosi commented Aug 29, 2019

Thank you.
I understand that this is a bug in Qt and will close this issue.

@akiyosi akiyosi closed this as completed Aug 29, 2019
@akiyosi
Copy link
Author

akiyosi commented Sep 10, 2019

I'd like to check again.

I tried to build using -qt_api 5.12.0, but the problem occurs again.
-qt_api is not effective in such cases?

And to avoid this situation temporarily, I'm thinking of building with a custom docker image.
Could I use a custom docker image for the build in qtdeploy -docker build ?

@akiyosi akiyosi reopened this Sep 10, 2019
@therecipe
Copy link
Owner

therecipe commented Sep 10, 2019

-qt_api and QT_API are just changing the Qt api, if you want to build against the Qt 5.12 libs while still using the Qt 5.13 api, then use -qt_version=5.12.0 -qt_api=5.13.0 or
QT_VERSION=5.12.0 QT_API=5.13.0 instead.
But depending on how you build the docker image, you will only need to set QT_API=5.13.0

To use a custom docker image, just tag it like this: therecipe/qt:windows_custom_image
and then use it like this qtdeploy -docker build windows_custom_image

But I will make some changes to make something like
qtdeploy -docker build akiyosi/qt:windows_custom_image work as well in the future.

Also btw, if you want to build a custom docker image with mxe and Qt 5.12, then you will just need to checkout some older commit here: https://github.com/therecipe/qt/blob/master/internal/docker/windows_64_shared/Dockerfile.base#L4
and then change this line here: https://github.com/therecipe/qt/blob/master/internal/docker/windows_64_shared/Dockerfile#L16
to copy from your custom base image.
The rest of the dockerfiles can probably stay the same.

edit: you could also use the windows_64_shared_512 image btw

@therecipe
Copy link
Owner

bc4f7f3 should make qtdeploy -docker build akiyosi/qt:windows_custom_image as well.
Just prefix the images names with windows_, linux_, android_, ...

@akiyosi
Copy link
Author

akiyosi commented Sep 14, 2019

Thank you very much for the polite explanation and support.
My understanding has become clearer.

edit: you could also use the windows_64_shared_512 image btw

I found that using the windows_64_shared_512 causes similar problems.
The problem may have started with 5.12.4 instead of 5.13.0 😨

Also btw, if you want to build a custom docker image with mxe and Qt 5.12, then you will just need to checkout some older commit here: https://github.com/therecipe/qt/blob/master/internal/docker/windows_64_shared/Dockerfile.base#L4
and then change this line here: https://github.com/therecipe/qt/blob/master/internal/docker/windows_64_shared/Dockerfile#L16
to copy from your custom base image.
The rest of the dockerfiles can probably stay the same.

I'm sorry, I wasn't sure what changes I should make to the above.
The source doesn't seem to handle any specific version of Qt.
how is the Qt version controlled?
Also, could i create the image with a specific version of Qt(e.g. Qt-5.12.3)?

@therecipe
Copy link
Owner

therecipe commented Sep 14, 2019

Sorry, mxe (the repo used to compile the cross compilable version of Qt) is always only supporting the latest version of Qt, so you would need to checkout an older commit (which for example still used Qt 5.12.3) of mxe first.

This one for example mxe/mxe@fb59cba#diff-51048c913ea268d97b588dbe368ea37d should work.
You can find the other Qt related commits from mxe here: https://github.com/mxe/mxe/commits/master/src/qtbase.mk

So you probably will only need to make these changes here:

diff --git a/internal/docker/windows_64_static/Dockerfile b/internal/docker/windows_64_static/Dockerfile
index f7d20c40..0ecccb1e 100644
--- a/internal/docker/windows_64_static/Dockerfile
+++ b/internal/docker/windows_64_static/Dockerfile
@@ -13,7 +13,7 @@ ENV QT_MXE_STATIC true
 COPY --from=therecipe/qt:linux /usr/local/go /usr/local/go
 COPY --from=therecipe/qt:linux $GOPATH/bin $GOPATH/bin
 COPY --from=therecipe/qt:linux $GOPATH/src/github.com/therecipe/qt $GOPATH/src/github.com/therecipe/qt
-COPY --from=therecipe/qt:windows_64_static_base /usr/lib/mxe /usr/lib/mxe
+COPY --from=akiyosi/qt:windows_64_static_base /usr/lib/mxe /usr/lib/mxe
 
 RUN $GOPATH/bin/qtsetup prep
 RUN $GOPATH/bin/qtsetup check windows
diff --git a/internal/docker/windows_64_static/Dockerfile.base b/internal/docker/windows_64_static/Dockerfile.base
index 144649f7..ea146099 100644
--- a/internal/docker/windows_64_static/Dockerfile.base
+++ b/internal/docker/windows_64_static/Dockerfile.base
@@ -1,7 +1,7 @@
 FROM ubuntu:16.04 as base
 
 RUN apt-get -qq update && apt-get --no-install-recommends -qq -y install ca-certificates git
-RUN git clone -q --depth 1 https://github.com/mxe/mxe.git /usr/lib/mxe
+RUN git clone -q https://github.com/mxe/mxe.git /usr/lib/mxe && cd /usr/lib/mxe && git checkout -f fb59cba9e2aa2aca8be0d92402adce14c3931af2
 RUN apt-get -qq update && apt-get --no-install-recommends -qq -y install autoconf automake autopoint bash bison bzip2 flex g++ g++-multilib gettext git gperf intltool libc6-dev-i386 libgdk-pixbuf2.0-dev libltdl-dev libssl-dev libtool-bin libxml-parser-perl make openssl p7zip-full patch perl pkg-config python ruby scons sed unzip wget xz-utils lzip
 
 RUN cd /usr/lib/mxe && make -j $(grep -c ^processor /proc/cpuinfo) MXE_TARGETS='x86_64-w64-mingw32.static' qt5 && rm -rf /usr/lib/mxe/log && rm -rf /usr/lib/mxe/pkg

Then build the two images with something like:

cd $(go env GOPATH)/src/github.com/therecipe/qt/internal/docker/windows_64_static
docker build -f Dockerfile.base -t akiyosi/qt:windows_64_static_base . 
docker build -f Dockerfile -t akiyosi/qt:windows_64_static .

and then use the final image like this: qtdeploy -docker build akiyosi:qt/windows_64_static

@akiyosi
Copy link
Author

akiyosi commented Oct 27, 2019

Sorry for the late reply.
I haven't created my custom build image yet, but I understand how to create a custom image.
I appreciate the detailed code and advice above.😀

@akiyosi akiyosi closed this as completed Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants