• 4911阅读
  • 3回复

关于图片显示的两个疑难问题(有程序代码),请高人指点! [复制链接]

上一主题 下一主题
离线aabb
 
只看楼主 正序阅读 楼主  发表于: 2008-07-23
— 本帖被 XChinux 执行加亮操作(2008-07-24) —
问题一:
我写了一段代码但是最后的效果不是我想要的,还请高人帮忙指点一下,谢谢啦!

void ClientInfoBase::openfile1()
{
    QString newfilename1 = QFileDialog::getOpenFileName( "",
        tr("Jpg File(*.jpg);;Bmp File(*.bmp);;Png File(*.png)"),
        this,
        "open files dialog"
        "Select one  file to open" );
    if ( !newfilename1.isEmpty() ) {
               
        textLabel1->setPixmap(newfilename1);     
        scrollArea->addChild(textLabel1);   
        scrollArea->setHScrollBarMode(QScrollView::ScrollBarMode::AlwaysOn);
        scrollArea->setVScrollBarMode(QScrollView::ScrollBarMode::AlwaysOn);
        scrollArea->show();   
       
    }
}
所要显示的图片没有在原来的窗口上显示,而是新打开了一个窗口,在新打开的窗口上显示了。怎样才能在原来的窗口上显示呢?还请高人指点,谢谢!


问题二:
void ClientInfoBase::openfile1()
{
    QString newfilename1 = QFileDialog::getOpenFileName( "",
        tr("Jpg File(*.jpg);;Bmp File(*.bmp);;Png File(*.png)"),
        this,
        "open files dialog"
        "Select one  file to open" );
    if ( !newfilename1.isEmpty() ) {     
   
        QScrollView* scrollArea = new QScrollView(this);   
        textLabel1=    new QLabel( scrollArea->viewport());    
        textLabel1->setPixmap(newfilename1);
        scrollArea->addChild(textLabel1);
        scrollArea->setHScrollBarMode(QScrollView::ScrollBarMode::AlwaysOn);
        scrollArea->setVScrollBarMode(QScrollView::ScrollBarMode::AlwaysOn);
       scrollArea->show();   
       
    }
}
显示的画面出现在原窗口的左上角,怎样才能使图片出现在原窗口的中间,或者是想要显示的位置呢?请高手指点!谢谢!
离线aabb
只看该作者 3楼 发表于: 2008-07-24
谢谢各位啦,
离线weizhy
只看该作者 2楼 发表于: 2008-07-24
要显示图片不用使用QLabel,
按你代码的意图来看,可以使用QGraphicsView + QGraphicsScene
在Scene上添加图片

而且使用这种方法可以非常灵活的设置各种位置,旋转等控制参数
具体可以参考assistans和qtdemo的相关内容
离线foxyz

只看该作者 1楼 发表于: 2008-07-24
麻烦贴出上下文代码!
你的 ClientInfoBase是什么?
textLabel1是什么?
scrollArea是什么?
快速回复
限100 字节
 
上一个 下一个