QLabel take full size into QToolBar - c++

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.

Related

QPushButton with Image not getting highlighted when focused (MAC)

I have a QPushButton with image, i have set focus policy to strong focus but, while focusing that QPushButton it is not getting highlighted(no dot frame or default blue border)
You should take a look at the QPalette(in Qt Designer) of your QPushButton and in particular, the HighLight color which is supposed to handle this effect. Moreover, make sure you didn't define focusPolicy in the stylesheet of a parent of that QPushButton, as that could cause problems, because QPushButton would inherit that property.

Qt: display an image (QLabel) inside a QScrollArea

I am trying to display an image inside a QScrollArea located on the QMainWindow.
I want a fixed size for the image display, and scroll bars to appear if the loaded image is bigger than the QScrollArea. My problem is that when I load an image which is bigger than the QScrollArea, the image appears cut (which is ok) but no scroll bars appear on the UI.
Taking into account various recommandations from other stackoverflow questions, here is the generated code from the Qt designer:
mImageScrollArea = new QScrollArea(centralWidget);
mImageScrollArea->setObjectName(QString::fromUtf8("mImageScrollArea"));
mImageScrollArea->setGeometry(QRect(440, 0, 400, 700));
mImageScrollArea->setWidgetResizable(false);
scrollAreaWidgetContents = new QWidget();
scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents"));
scrollAreaWidgetContents->setGeometry(QRect(0, 0, 398, 698));
mLabel = new QLabel(scrollAreaWidgetContents);
mLabel->setObjectName(QString::fromUtf8("mLabel"));
mLabel->setGeometry(QRect(0, 0, 400, 700));
QSizePolicy sizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(mLabel->sizePolicy().hasHeightForWidth());
mLabel->setSizePolicy(sizePolicy);
mLabel->setScaledContents(true);
mImageScrollArea->setWidget(scrollAreaWidgetContents);
When an image is loaded, I display it in the label as follow:
QPixmap wPixmap = QPixmap::fromImage(mImage);
ui.mLabel->resize(wPixmap.size());
ui.mLabel->setPixmap(wPixmap);
ui.mLabel->show();
Why aren't any scrollbars showing if the image I load is bigger than the QScrollArea ?
It would be more helpful if you provide UI file content instead of generated C++ code. Anyway, it seems that scrollAreaWidgetContents doesn't have a layout. You need to add a grid layout to it in Qt Designer. After you do this, you will not need to resize label or scrollAreaWidgetContents manually. They will be resized automatically. Calling show on label is not required either, it will be visible by default (unless you have hid it).

Qt designer and draw rectangle on screen

Please see the following picture:
In above picture, i specefied a rectangle, i need to draw same rectangle in my program with Qt-Designer, But i don't know to use what widget.
Can i use qt designer or i should just use code?
Notes: I attemp to use QLabel and put --- and | but they don't stick.
My question is , Which widget can help me?
The box that you have circled in the image is a QGroupBox, and can be created using the QtDesigner. Other widgets can then be inserted into like any other widget that supports layouts.

how to attach image to gui created by using Qt creator

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().

how to dynamically add a QWidget based to QGraphicsScene?

I want to add a QWidget based class(composed by buttons and labels an so on...) to my QGraphicScene scene in a special position and respecting the graphic style of my scene.?
I am using QT 4.7.
You may use QGraphicsScene::addWidget() to add your widget to the scene and use the returned QGraphicsProxyWidget * to reposition your widget with QGraphicsItem::setPos().
Alternatively, you may look into QGraphicsWidget class.