QT ScrollBars doesn't appear with scrollAreaWidgetContents - c++

I am trying to learn QT with visual studio. My development environment is VS2015 with QT designer. I am trying to do the following tutorial.
http://www.bogotobogo.com/Qt/Qt5_QMainWindow_QAction_ImageViewer_B.php
essentially the tutorial displays an image with Qlabel and QScrollArea. If I create the widgets with code (using visual studio) the program seems to work.
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);
However, then I tried to do the same with QT Designer. When I dragged a ScrollArea from QT Designer, I notices that it also created a QWidget called "scrollAreaWidgetContents". Then when I created the QLabel, Label was created under "scrollAreaWidgetContents" widget. I then tried to display the image using the following 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);
The problem with this is that the scroll Bars never appears. See the attached
Then I uncommented "ui->scrollArea->setWidget(ui->label);" line and then the program compiles but crashes. So, how do I make the scrollBars appear with QT Designer? What am I doing wrong.
Thanks for the help

Related

QPushButton in UI form file: image doesn't show when adding resource, but shows when setting stylesheet

I have a Qt widgets project which defines dialog boxes with Qt Designer UI files. In one dialog box I include a QPushButton and I added an image by going to "QAbstractButton"->"Icon" and setting the file to "normal on". Afterwards I've noticed that, even though that image is rendered in Qt Designer, it does not show up when I compile and run the project.
However, the same exact resource is rendered in the button if I set it using Qt's stylesheets.
qproperty-icon: url(:/Resources/icn_MyIcon.png)
I'd much prefer to not use stylesheets for simple things like adding an image to a button. Does anyone have any idea why setting resources with Qt Designer fails but setting stylesheets works?

Focus not seen in Qt for Qdial subclass

I am using Qt in Visual Studio to get an interface with buttons and knobs etc. I am using this SkinnedDial class - http://dronecolony.com/2012/12/11/customized-qdial-with-qss-support/ , to get a QDial with a custom image. But the problem is that while the other controls are showing the focus frame when I tab over them, this control does not show the focus - for instance button shows the rectangle, but nothing shows up for the dial. Here's the code segment for the dial -
SkinnedDial *myDial;
...
myDial = new SkinnedDial(this);
myDial->setRange(-100, 100);
QPixmap *bg = new QPixmap();
bg->load("C:/Current/dial.png");
QPixmap *nl = new QPixmap();
nl->load("C:/Current/needl.png");
myDial->setBackgroundImage(*bg);
myDial->setNeedleImage(*nl);
myDial->setMaxAngle(100);
I am new to Qt and C++ and I'm not sure how to solve this problem.

QQuiickWidgets within TabWidgets crashes when rendering OpenGL code

QQuickWidgets embedded in QTabWidget container, crashes upon rendering custom OpenGL code, via QML, QQuickItem and QSGNode.
The crash or scene flickering happens when you click on the other tabs on the QTabWidget and return back to the rendering tab.
QQuickWidget* m_quickWidget = new QQuickWidget;
QTabWidget *tabs = new QTabWidget(this);
tabs->addTab(m_quickWidget,"TAB Rendering");
tabs->addTab(new QWidget(),"TAB 1");
m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView );
m_quickWidget->setSource(source);
setCentralWidget(tabs);
The above scenario runs peacefully without any problem when using QQuickViews:
QTabWidget *tabs = new QTabWidget(this);
QWidget* vw = QWidget::createWindowContainer(m_quickWidget);
tabs->addTab(vw,"TAB Rendering");
tabs->addTab(new QWidget(),"TAB 1");
I have attached a qt project for emphasizing the problem
back trace for more info
Hi we have seen similar things including the black flickering, however 5.5 seems to have made that black flicker go away. Have you tried that?
Also, I would recommend that you post it on the Qt bug tracker so that someone from the Qt dev team can recreate and fix the problem.

Placing buttons at the center in horizontal line in QT

I am new QT and trying to develop the desktop application.
Currently I am facing a issue of alignment. I am using QTCreator 3.1.2 based on qt 5.3.1
I have 3 buttons placed in the windows as
After running application, If I resize the windows then buttons didn't stay in the center. like image 1 and if size is less then it is like image 2
I have tried using the hbox, but it didn't solve the problem and also scroll bar is also not visible in the window.
Would you please tell me how can I make these buttons to stay in the center only?
Thanks a lot
You can create QHBoxLayout passing this as its parent, which will set that layout as the layout of that widget, then add QPushButtons to that layout:
Widget::Widget(QWidget *parent) : QWidget(parent) {
// Prepare the horizonal layout, adding buttons
horizontalLayout = new QHBoxLayout(this);
pushButton = new QPushButton(this);
horizontalLayout->addWidget(pushButton);
pushButton_2 = new QPushButton(this);
horizontalLayout->addWidget(pushButton_2);
pushButton_3 = new QPushButton(this);
horizontalLayout->addWidget(pushButton_3);
// Set the layout of the central widget
setLayout(horizontalLayout);
}

QLabel take full size into QToolBar

I want to put QLabel into QToolBar. I do that but the QLabel changes QToolBar size, and does not fill it, see the first image below. What I need is make QLabel fill the QToolBar and resize the image, to be the same size as QLabel and QToolBar.
screenshot of what I want to happening:
I'm working with Qt 5.1, MinGw 4.8, and image type is .gif.
Are you sure you must to use QLabel? Perhaps you should set the background image using Qt style sheets.
Link to customizing QToolBar.