• 3649阅读
  • 4回复

[提问]Label显示图片怎么只显示某一个部分? [复制链接]

上一主题 下一主题
离线斯托普李
 

只看楼主 倒序阅读 楼主  发表于: 2015-06-04
#include "mainwindow.h"#include <QApplication>#include <QHBoxLayout>#include <QVBoxLayout>#include <QPushButton>#include <QLabel>#include <QPixmap>int main( int argc, char **argv ){    QApplication a(argc,argv);    QWidget w;    QHBoxLayout *hl=new QHBoxLayout;    QLabel *label=new QLabel;    QPixmap pixmap(":/new/prefix1/puke");    pixmap.copy(pixmap.rect().x(),pixmap.rect().y(),80,80);    hl->addWidget(label);    label->setPixmap(pixmap);    w.setLayout(hl);    w.show();    return a.exec();}
//网上查了下是用copy函数 可是这样运行后 还是显示的整张图片啊 该怎么写?
离线斯托普李

只看该作者 1楼 发表于: 2015-06-04
擦 第一次发帖 怎么是这种显示
离线斯托普李

只看该作者 2楼 发表于: 2015-06-04
#include "mainwindow.h"
#include <QApplication>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QPixmap>
int main( int argc, char **argv )
{
    QApplication a(argc,argv);
    QWidget w;
    QHBoxLayout *hl=new QHBoxLayout;
    QLabel *label=new QLabel;
    QPixmap pixmap(":/new/prefix1/puke");
    pixmap.copy(pixmap.rect().x(),pixmap.rect().y(),80,80);
    hl->addWidget(label);
    label->setPixmap(pixmap);
    w.setLayout(hl);
    w.show();
    return a.exec();
}
离线xuang

只看该作者 3楼 发表于: 2015-06-04
copy返回的才是你要的局部Pixmap
离线斯托普李

只看该作者 4楼 发表于: 2015-06-04
回 xuang 的帖子
xuang:copy返回的才是你要的局部Pixmap (2015-06-04 14:59) 

...我说我怎么老犯低级失误
快速回复
限100 字节
 
上一个 下一个