更改图像的大小以适应 GUI 窗口的新大小
changing image's size to fit the new size of the GUI window
我已经阅读了Qt调整大小策略的文档,但我找不到如何实现改变图像大小以适应Qlabel新大小的场景。
这是我的GUI结构
mainLayout:
toplayout:
QLabel
QPushButton
现在我有了cv::Mat
图像。我已转换为QPixmap
。
Window::Window(QWidget *parent): QDialog(parent)
{
// Widgets
browserButton = new QPushButton(tr("Open"));
imageLabel = new QLabel;
imageLabel->setAlignment(Qt::AlignHCenter);
imageLabel->setScaledContents(true);
// Connect Actions
connect(browserButton, SIGNAL(clicked()), this, SLOT(browserClicked()));
// Layouts
QVBoxLayout *topLayout = new QVBoxLayout;
topLayout->addWidget(imageLabel);
topLayout->addWidget(browserButton);
// Main Layout
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(topLayout);
setLayout(mainLayout);
setWindowTitle("Image Browser");
}
这是按钮
void Window::browserClicked()
{
// Get file name as QString
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Image"),
NULL,
tr("Image Files (*.png *.jpeg *.jpg *.bmp)"));
// Read file name as String not QString and store the image
m_original_CVimg = cv::imread(fileName.toStdString());
imageLabel->setPixmap(this->cvMatToQPixmap(m_original_CVimg));
}
我想在每次用户改变窗口大小时重新调整图像的大小。如果我扩大窗口,图像也会扩大,但问题是如果我缩小窗口,窗口的大小就会受到图像大小的限制。任何建议
看一下QResizeEvent
相关文章:
- 在 Gui Win32 中创建子窗口C++
- 有没有办法拿一个opencv显示窗口并将其保存到GUI窗口?
- gtkmm在班上以外地关闭GUI窗口
- QTCreator GUI应用程序中包含窗口基源代码并在代码中打开
- 使用第二个线程快速更新 GUI 窗口会通过调整窗口大小或移动窗口而崩溃
- win32 GUI 在窗口中显示来自字符数组变量的文本
- 使用C++Win32 GUI在窗口中显示文本
- 如何在Qt GUI应用程序中嵌入输出控制台窗口
- QML 打开 GUI 窗口和控制台
- GUI 和 RAII:通过析构函数或窗口关闭、窗口生命周期进行 Cleenup
- C++ GUI 窗口位置
- 当gui程序向cli程序发送命令时,隐藏控制台窗口
- win32 GUI 在窗口中显示来自 int 变量的数字
- 好奇心:背景C++窗口.SFML/SDL类型和Qt(GUI)类型之间的差异
- visual studio中用于复杂表单的C++可扩展GUI窗口
- 如何使用Visual studio将OpenCV图像查看窗口推送到QT GUI中
- 更改图像的大小以适应 GUI 窗口的新大小
- 加载主QT/QML GUI窗口减慢了启动画面的渲染速度
- 在Qt中制作一个关于GUI窗口的游戏
- GUI 窗口屏幕截图从 C/C++ 到内存