agaf
19th January 2010, 14:57
I need QScrollArea to contains some images
TestScrollArea::TestScrollArea(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
QWidget* widget = new QWidget;
QVBoxLayout* layout = new QVBoxLayout( widget);
QImage image("D:\\data\\photo\\me\\bg2009.jpg");
Q_ASSERT( image.isNull() == false);
QLabel* label1 = new QLabel;
label1->setPixmap( QPixmap::fromImage( image));
layout->addWidget( label1);
ui.scrollArea->setBackgroundRole(QPalette::Dark);
ui.scrollArea->setWidget( widget);
}
This code was placed to the main window constructor and it worked ok (image displayed). Then I created QScrollArea child class and moved the code to its contructor:
TestImageViewer::TestImageViewer(QWidget *parent)
: QScrollArea(parent)
{
QWidget* widget = new QWidget;
QVBoxLayout* layout = new QVBoxLayout( widget);
QImage image("D:\\data\\photo\\me\\bg2009.jpg");
Q_ASSERT( image.isNull() == false);
QLabel* label1 = new QLabel;
label1->setPixmap( QPixmap::fromImage( image));
layout->addWidget( label1);
setBackgroundRole(QPalette::Dark);
setWidget( widget);
}
Now I see nothing except a grey rectangle. What I'm doing wrong?
TestScrollArea::TestScrollArea(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
QWidget* widget = new QWidget;
QVBoxLayout* layout = new QVBoxLayout( widget);
QImage image("D:\\data\\photo\\me\\bg2009.jpg");
Q_ASSERT( image.isNull() == false);
QLabel* label1 = new QLabel;
label1->setPixmap( QPixmap::fromImage( image));
layout->addWidget( label1);
ui.scrollArea->setBackgroundRole(QPalette::Dark);
ui.scrollArea->setWidget( widget);
}
This code was placed to the main window constructor and it worked ok (image displayed). Then I created QScrollArea child class and moved the code to its contructor:
TestImageViewer::TestImageViewer(QWidget *parent)
: QScrollArea(parent)
{
QWidget* widget = new QWidget;
QVBoxLayout* layout = new QVBoxLayout( widget);
QImage image("D:\\data\\photo\\me\\bg2009.jpg");
Q_ASSERT( image.isNull() == false);
QLabel* label1 = new QLabel;
label1->setPixmap( QPixmap::fromImage( image));
layout->addWidget( label1);
setBackgroundRole(QPalette::Dark);
setWidget( widget);
}
Now I see nothing except a grey rectangle. What I'm doing wrong?