如何重新缩放图像并将其设置为 QWidget
How can I rescale an image and set it to QWidget?
QPixmap pic("../image.jpg");
setAutoFillBackground(true);
QPalette palette;
QPixmap scaled=pic.scaled ( 800, 480, Qt::IgnoreAspectRatio, Qt::FastTransformation );
palette.setBrush(QPalette::Window, QBrush(scaled));
//this->setPalette(palette);
QWidget *w= new QWidget(this);
w->setGeometry(0,0,800,480);
w->show();
w->setPalette(palette);
但是小部件不显示任何图像。
您只是想在小部件中显示缩放的图像吗? 我不认为在画笔中设置图像然后在调色板中设置画笔是正确的方法。
您可以使用QLabel在小部件中显示图像。 喜欢这个:
QPixmap pic("../image.png");
QPixmap scaled=pic.scaled ( 800, 480, Qt::IgnoreAspectRatio, Qt::FastTransformation );
QLabel *label = new QLabel(this);
label->setPixmap(scaled);
您在设置调色板之前显示小部件。首先尝试设置调色板。
如果这没有帮助,请尝试指定完整的文件路径。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 在C++/Linux中设置单调时钟的一些技巧
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 嵌套在类中时无法设置成员数据
- 需要帮助设置在C++中使用的Potrace
- 如何在自删除后将对象设置为nullptr
- 将指针设置为"nullptr"并不能防止双重删除?
- 为提升的小部件设置父 QWidget
- 无法在 qt 中为 QWidget 中的派生类设置样式表
- 为 QWidget 的私有成员设置样式表
- QWidget - 从C++代码设置边框
- 在设置QStylesHeet之后,如何获得Qwidget背景色
- 如何为Qwidget设置用户数据
- 如何设置通知功能,以便在创建QWidget派生对象时触发
- 是否可以继承QVBoxLayout并将其设置为QWidget中的布局
- 如何在 QGraphicsWidget 中设置 Qwidget
- Qt设置QWidget的默认宽度
- 如何重新缩放图像并将其设置为 QWidget
- Qt -使用QWidget类设置QWidget
- 设置了布局,但是QWidget看起来仍然是空的