pyapp-kit / magicgui

build GUIs from type annotations
https://pyapp-kit.github.io/magicgui/
MIT License
371 stars 49 forks source link

DirectWrite: CreateFontFaceFromHDC() failed #653

Closed hjroyal closed 3 months ago

hjroyal commented 4 months ago

1. Environment :

2. Problem: I followed the tutorial on the official website and tried to run the following example code to get an error.

DirectWrite: CreateFontFaceFromHDC() failed (指示输入文件 (例如字体文件) 中的错误。) for QFontDef(Family="MS Sans Serif", pointsize=12, pixelsize=16, styleHint=5, weight=400, stretch=100, hintingPreference=0) LOGFONT("MS Sans Serif", lfWidth=0, lfHeight=-16) dpi=96

# test.py

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.backends.backend_qt5agg import FigureCanvas

from magicgui import magicgui

x = np.linspace(0, 5, 256)
y = np.linspace(0, 5, 256)[:, np.newaxis]
data = np.sin(x) ** 10 + np.cos(10 + y * x) * np.cos(x)

mpl_fig = plt.figure()
ax = mpl_fig.add_subplot(111)
(line,) = ax.plot(data[123])  # linescan through the middle of the image

@magicgui(position={"widget_type": "Slider", "max": 255}, auto_call=True)
def f(position: int):
    """Function demonstrating magicgui combined with matplotlib."""
    line.set_ydata(data[position])
    line.figure.canvas.draw()

# rather than using the Container.append (`f.append`) ...
# grab the native layout and add the QWidget to it
f.native.layout().addWidget(FigureCanvas(mpl_fig))

f.show(run=True)

3. Actions: pip install magicgui pip install PyQt5 run test.py

tlambert03 commented 4 months ago

hi @hjroyal, it's hard to tell what this issue is. is this a bug report? if so, please tell me what code you ran to get this error, and if that DirectWrite line is an exception you received, please give the full traceback

hjroyal commented 4 months ago

Yes. Thank you for your reply. I updated my question and I guess it's a Windows 11 problem.

tlambert03 commented 4 months ago

thank you. Ultimately, this is likely to be a broader Qt problem for you, and not a magicgui issue. However, if you can give me the full error message, including the traceback (i.e. NOT just the bit including DirectWrite: CreateFontFaceFromHDC() ... but rather the entire error message, including file names and line numbers) I might be help a bit more

hanjinliu commented 4 months ago

@hjroyal I think it's a windows x Qt issue. It's not an error but a log output by Qt at C++ level.

tlambert03 commented 4 months ago

It's not an error but a log output by Qt at C++ level.

ahh, is that true @hjroyal? Does the example otherwise work? You're just seeing this printed to your console?