how to attach image to gui created by using Qt creator - c++

How to put an image on the GUI created by Qt?
The south west part of the screen is empty so I want a picture to be put there on a click of a button but I am unable to use QPixmap and setPixmap. Please help me with this !

Use QLabel in Qt Creator
Then Go to Properties of QLabel
Go to Pixmap
Select the file
Its done.

You can create a QWidget or a QFrame at the place you want to add an image. You can then use the style sheet to set a background-image on that picture. You might want to add your image to your ressources (.qrc).
Using QtDesigner is a good idea for this kind of task.
EDIT :
Here is an easy way to do that without bothering with QPixMap.
QWidget *frame = new QWidget(this);
frame->setGeometry(x, y, width, height);
frame->setStyleSheet("background-image: url(:/path/to/image.png)");
The : specifies that you want to use the path in your Qt resources. The first two lines are not needed if you define this QWidget using QtDesigner.
Also, don't forget to import your resources.qrc (however you called it) file (including your resources) and add this to your .pro :
RESOURCES = resources.qrc

You should use a label (QLabel). You can add a label to your form and edit its pixmap property in Qt Designer (you will be able to choose one of images you've added to project resources). Also you can set an image on QLabel programmatically using setPixmap().

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?

The background image is not drawn QWidget

The application has 2 windows. One thing is MainWindow, for which a png image is set as the background through QtStyleSheet. In the class itself, the attributes Qt::WA_TranslucentBackground and Qt::FramelessWindowHint. The second is QWidget, which serves to configure the application. The problem is that in Qt Creator QWidget background image displayed normally, and when you start the application, it is empty. Images used as a background are in the resource file.
(Sorry there is not enough rating to attach images)
Here is an example:
So the background looks like in Qt Creator
And so when you start the application
What could be the problem, and how to find its cause?

Qt pushbutton palette

I'm using GUI form editor in qt creator, I have set the background
(right_click -> change_stylesheet->Add Resource -> background_image)
Then I added a few buttons, the buttons are colored like the background, instead of being normal - default. I was trying this with properties->palette but with poor results. I'm new to qt, so I am asking for your help.
Like in CSS, Qt Style Sheet will apply your styling rules to any item that matches them.
If you just write:
background-image: url(:/my_background.png);
it will change the background of all the widgets in your application.
If you want to change the background of the main window only, you should write:
QMainWindow {
background-image: url(:/my_background.png);
}
That will apply the background image only to the QMainWindow object.
For an detailed explanation of Qt Style Sheet, I invite you to read the official documentation here.

QT window within window?

I'm setting up a small code editor using QT and following this example. However, i'm curious on how to create windows within windows or widgets within widgets. I'm trying to achieve something similar to these:
http://i.stack.imgur.com/Vn8Ut.png
http://www.hanselman.com/blog/content/binary/Windows-Live-Writer/Download-Visual-Studio-2013-while-your-f_1431E/image_4eb5427c-1ae7-4464-9c26-2282fe8d06c3.png
Is there an example of overlaying widgets like this?
Any alternative soloution for QMessagebox for IOS development (QWidget application only)?
I gave an example of getting another QWidget to be embedded and painted on top of another one. Let me know if you have any questions about how it was done.
The PopUp flag and Qt::Tool options are also relevant.
Be sure to check out: the ToolTip property of a QWidget and the WhatsThis property of QWidget.
http://qt-project.org/doc/qt-5/qwidget.html#toolTip-prop
http://qt-project.org/doc/qt-5/qwidget.html#whatsThis-prop
There are also other ways to make borderless, focusless windows that hover and disappear quickly on command. The Window Flags and Widget Attributes in Qt are very powerful when you are looking to modify Qt Widgets.
When you parent a Widget to another widget, it will draw itself on top of the other. Then you just need to resize and position it properly.
Also subclassing existing widgets can give you more options.
Draw text on scrollbar
Also common Qt::Tools that you will find are QDockWidgets. They are awesome!
Hope that helps.
Take a look at Qt Namespace especially Qt::WA_LayoutOnEntireRect and Qt::WA_StyleSheet. Pass it as a widget attrybutes. The second option looks promising but you have to create style sheet for QWidget.

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.