zoukankan      html  css  js  c++  java
  • Qt 设置背景图片反走样两种方法

    说明:本次实验采用QPainter和QPalette两种方法实现背景反走样

    方法一:

    采用画笔QPainter

    //QPainter::Antialiasing           告诉绘图引擎应该在可能的情况下进行边的反锯齿绘制
    //QPainter::TextAntialiasing       尽可能的情况下文字的反锯齿绘制
    //QPainter::SmoothPixmapTransform  使用平滑的pixmap变换算法(双线性插值算法),而不是近邻插值算法
    painter.setRenderHint(QPainter::Antialiasing, true);

    方法二:

    采用调色板QPalette

    //不失真缩放方法
    scaled(width,height,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
    //第一、二参数代表缩放后的尺寸,第三个参数代表忽略比例,也可调用IgnoreAspectRatio保持长宽比例,第四个参数代表平滑处理,使图片缩小时不失真。

    /* 设置背景图片 */
        QPixmap pixmap = QPixmap(QString::fromUtf8(":/image/Image/罗盘背景1.png"))
                .scaled(ui->qwtPlot->size(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
        QPalette palette;
        palette.setBrush(QPalette::Background, QBrush(pixmap));//backgroundRole()
        ui->qwtPlot->setStyleSheet(QString::fromUtf8("border:none;"));//去除边框
        ui->qwtPlot->setPalette(palette);
        ui->qwtPlot->setAutoFillBackground(true);

    附加:去除控件边框

        ui->qwtPlot->setStyleSheet(QString::fromUtf8("border:none;"));//去除边框
  • 相关阅读:
    第10组 Alpha冲刺(4/6)
    第10组 Alpha冲刺(3/6)
    第10组 Alpha冲刺(2/6)
    第10组 Alpha冲刺(1/6)
    第10组 团队Git现场编程实战
    第10组 团队项目-需求分析报告
    团队项目-选题报告
    【软件工程】Alpha冲刺(4/6)
    【软件工程】Alpha冲刺(3/6)
    【软件工程】Alpha冲刺(2/6)
  • 原文地址:https://www.cnblogs.com/shuoguoleilei/p/11660216.html
Copyright © 2011-2022 走看看