nipunamr
27th October 2017, 17:27
My development environment is Visual studio 2015 with QT 5.6.3. I am creating forms using QT designer. I am doing several QT tutorials; specifically I am doing the following tutorial.
http://www.bogotobogo.com/Qt/Qt5_QMainWindow_QAction_ImageViewer_B.php
The program essentially, displays an image using QScrollArea and QLabel. The program works if I create my "widgets" in visual studio (without QT designer)
//Here's the relevant code
imageLabel = new QLabel;
imageLabel->setBackgroundRole(QPalette::Base);
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabel->setScaledContents(true);
scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(imageLabel);
setCentralWidget(scrollArea);
As expected the scrollbars appear.
Then I created the widgets in QT Designer and tried to use it in visual studio. The one thing I noticed is that when I create a scrollArea using QT designer it also creates a QWidget called "ScrollAreaWidgetContents". See the attached "QT_Designer_1" and "QT_Inspector_Window" images. The problem is that I can't see scroll bars with this program. See the attached "Image_Viewer_No_ScrollBars". Here's the releavant code.
ui->label->setBackgroundRole(QPalette::Base);
ui->label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
ui->label->setScaledContents(true);
ui->scrollArea->setBackgroundRole(QPalette::Dark);
ui->scrollArea->setWidget(ui->scrollAreaWidgetContents);
ui->scrollArea->setWidgetResizable(true);
ui->scrollAreaWidgetContents->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
//ui->scrollArea->setWidget(ui->label);
setCentralWidget(ui->scrollArea);
I then tried to uncomment "ui->scrollArea->setWidget(ui->label)" line and the program crashes. See the attached "Image_Viewer_Crashes" I guess I don't understand why it's crashing. Could anyone help resolve this problem?
Thanks
http://www.bogotobogo.com/Qt/Qt5_QMainWindow_QAction_ImageViewer_B.php
The program essentially, displays an image using QScrollArea and QLabel. The program works if I create my "widgets" in visual studio (without QT designer)
//Here's the relevant code
imageLabel = new QLabel;
imageLabel->setBackgroundRole(QPalette::Base);
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabel->setScaledContents(true);
scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(imageLabel);
setCentralWidget(scrollArea);
As expected the scrollbars appear.
Then I created the widgets in QT Designer and tried to use it in visual studio. The one thing I noticed is that when I create a scrollArea using QT designer it also creates a QWidget called "ScrollAreaWidgetContents". See the attached "QT_Designer_1" and "QT_Inspector_Window" images. The problem is that I can't see scroll bars with this program. See the attached "Image_Viewer_No_ScrollBars". Here's the releavant code.
ui->label->setBackgroundRole(QPalette::Base);
ui->label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
ui->label->setScaledContents(true);
ui->scrollArea->setBackgroundRole(QPalette::Dark);
ui->scrollArea->setWidget(ui->scrollAreaWidgetContents);
ui->scrollArea->setWidgetResizable(true);
ui->scrollAreaWidgetContents->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
//ui->scrollArea->setWidget(ui->label);
setCentralWidget(ui->scrollArea);
I then tried to uncomment "ui->scrollArea->setWidget(ui->label)" line and the program crashes. See the attached "Image_Viewer_Crashes" I guess I don't understand why it's crashing. Could anyone help resolve this problem?
Thanks