问题陈述说明了一切。我能够放大QMdiSubWindow(并且像素图缩放UP,即适当地放大)但我无法缩小其大小(即缩小图像DOWN或收缩)。当尝试缩小时,QMdiSubWindow的边框句柄仍然严格固定。
我使用的代码如下:
class PixmapWidget : public QLabel
{
Q_OBJECT
public:
PixmapWidget():
QLabel()
{
_pixmap = QPixmap("path\\to\\image.jpg");
setPixmap(_pixmap);
_layout = new QHBoxLayout();
_layout->setSizeConstraint(QLayout::SetNoConstraint);
setLayout(_layout);
setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
}
void resizeEvent(QResizeEvent * event)
{
int width = event->size().width();
int height = event->size().height();
setPixmap(_pixmap.scaled(width,height));
QLabel::resizeEvent(event);
}
protected:
QPixmap _pixmap;
QHBoxLayout* _layout;
};
int main()
{
QMainWindow mainWindow;
QHBoxLayout* layout = new QHBoxLayout();
QMdiArea* mdiArea = new QMdiArea();
mainWindow.setCentralWidget(mdiArea);
mainWindow.centralWidget()->setLayout(layout);
layout->setSizeConstraint(QLayout::SetNoConstraint);
QMdiSubWindow* mdiSubWindow = new QMdiSubWindow();
layout->addWidget(mdiSubWindow);
mdiSubWindow->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
mdiSubWindow->layout()->setSizeConstraint(QLayout::SetNoConstraint);
DMSQt::PixmapWidget pixmapWidget;
mdiSubWindow->layout()->addWidget(&pixmapWidget);
mainWindow.show();
qapp.exec();
}
答案 0 :(得分:1)
好吧,我发现了问题。显然,我需要在文本标签上设置最小尺寸:
添加:
setMinimumSize(_pixmap.width(), _pixmap.height());
解决了这个问题。