Qt QQuickImageProvider“;“请求的大小”;总是无效的
我请求了我的个人imageprovider,但是当我调试这几行时,requestedSize总是Qt QQuickImageProvider“;“请求的大小”;总是无效的,qt,qml,qt5,qtquick2,Qt,Qml,Qt5,Qtquick2,我请求了我的个人imageprovider,但是当我调试这几行时,requestedSize总是{-1,-1} class XdgIconThemeImageProvider : public QQuickImageProvider { public: XdgIconThemeImageProvider() : QQuickImageProvider(QQuickImageProvider::Pixmap){} QPixmap requestPixmap(const QStrin
{-1,-1}
class XdgIconThemeImageProvider : public QQuickImageProvider
{
public:
XdgIconThemeImageProvider() : QQuickImageProvider(QQuickImageProvider::Pixmap){}
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{
QIcon ico = QIcon::fromTheme(id);
QPixmap pm = ico.isNull() ? QPixmap() : ico.pixmap(100,100);
*size = pm.size();
return pm;
}
};
qmlfile
Image {
id: icon
source: model.decoration
width: parent.height
height: width
anchors.centerIn: parent
}
我做错什么了吗?这是传递给Image QML元素的
sourceSize
属性的内容
如何处理该值:若(!requested_size.isValid()| requested_size.isNull())
则给出本机大小,否则放入requested_size
。请求的_size
的一个组件中的零表示相应的维度是无界的
如何处理该值(假设本机大小(纹理句柄)
返回图像的默认大小):
此代码与标准实现稍有不同,因为它允许返回大于其本机大小的图像。适用于纹理,但在您的情况下可能需要,也可能不需要。requestedSize是否取决于如何从QML请求图像?如果是这样的话,我们必须查看声明映像的QML代码。更新了问题。因此,我的观点是,可能是映像导致了问题。你应该提供一个最小的,有效的例子。这有点误导。您是指qml
图像还是要显示的图像?两者见上文。fromTheme(id)获取图标并创建pixmap。model.decoration是类似“的url”image://XdgIconThemeImageProvider/myImageId". myImageId对应于Freedesktop图标主题规范。一般来说,这只不过是QIcon::fromTheme允许的输入。我们需要一个最小的运行示例,以便我们可以检查图像的宽度
和高度
的值。据我所知,我们没有足够的信息来帮助你。
const QSize size = native_size(texture_handle);
if (requested_size.isValid()) {
const QSize bounding_size(requested_size.width() > 0 ? requested_size.width() : size.width(), requested_size.height() > 0 ? requested_size.height() : size.height());
// If requested_size.isEmpty() then the caller don't care how big one or two dimensions can grow.
return size.scaled(bounding_size, requested_size.isEmpty() && (requested_size.width() > size.width() || requested_size.height() > size.height()) ? Qt::KeepAspectRatioByExpanding : Qt::KeepAspectRatio);
} else {
return size;
}