search

Home  >  Q&A  >  body text

c++ - qt中使用图片不能铺满窗口

我尝试在窗口中添加图片并且铺满窗口,

但是在实际运行过程中显示成了这样

尝试改变目标矩形的大小也没有作用

高洛峰高洛峰2767 days ago834

reply all(3)I'll reply

  • 高洛峰

    高洛峰2017-04-17 13:51:06

    You should scale QPixmap. This function has methods scaledToWidth and scaledToHeight

    QPixmap QPixmap::scaledToWidth(int width, Qt::TransformationMode mode = Qt::FastTransformation) const
    
    Returns a scaled copy of the image. The returned image is scaled to the given width using the specified transformation mode. The height of the pixmap is automatically calculated so that the aspect ratio of the pixmap is preserved.
    
    If width is 0 or negative, a null pixmap is returned.
    

    Scale the image before drawing

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:51:06

    Is the QPainter painter(this) in your this here the window of your wuziqi?

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:51:06

    Your qipan control does not cover the entire window...

    reply
    0
  • Cancelreply