【问题标题】:width/height ratio preserved after a call to qtextimageformat.setWidth()?调用 qtextimageformat.setWidth() 后保留的宽度/高度比?
【发布时间】:2014-08-21 15:35:32
【问题描述】:

为了在 QTextDocument 中插入图像,我必须修改它的宽度和高度并保持原始图像的比例。因此我的代码:

qtextimageformat.setWidth( new_width );
cursor.insertImage( qtextimageformat, position )

我认为修改宽度和高度是强制性的,但令我惊讶的是,对 .setWidth() 的调用以某种方式保留了图像的比例,就好像隐式调用了 .setHeight()使用正确的参数。

这是预期的行为吗?或者我错过了什么? The documentation 没有帮助我。

【问题讨论】:

    标签: qt5 image-resizing qimage qtextdocument


    【解决方案1】:

    这是预期的行为,即使文档中没有明确说明。 qtextimagehandler.cpp 中的静态函数 QSize getImageSize(QTextDocument *doc, const QTextImageFormat &format)QSize getPixmapSize(QTextDocument *doc, const QTextImageFormat &format) 如果仅在 QTextImageFormat 中指定宽度(反之亦然),则会自动推断高度

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-03
      • 2014-07-01
      • 1970-01-01
      • 2014-04-17
      • 2014-02-12
      • 1970-01-01
      相关资源
      最近更新 更多