QTextEdit 设置背景图片与拉伸背景图片

来源:互联网 发布:python 写文本文件 编辑:程序博客网 时间:2024/04/29 13:23

首先,通过一个文件选择对话打开一张图片,然后把这张图片设置为编辑框背景。参考具体代码: 

 

   QString name = QFileDialog::getOpenFileName(this, tr("Open File..."),
                                    QString(), tr("IMAGE-Files (*.jpg *.png *.gif *.bmp *.jpeg)"));

    if (name.length() > 0)
    {
     mBackPicName = name;
     mBackPic = new QPixmap(name);
        if (mBackPic == 0)
            return;
        QPalette palette = m_ui->con_edit_example->palette();
        palette.setBrush(QPalette::Base, QBrush((mBackPic->scaled(m_ui->con_edit_example->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation))));
        m_ui->con_edit_example->setPalette(palette);
        //m_ui->con_edit_example->setAutoFillBackground(FALSE);
        update();
    }

原创粉丝点击