Color the Image setting on QProgressBar - c++

Actually I set an image on a QProgressBar and want to change the color of image according to selected part of QProgressBar.
I tried covering my image with QProgressBar color but that fills the image, but as my image is not a rectangle it color the whole QProgressBar and not just the image.
Is it possible to change color of image only using qt (with C++)

You are looking for Qt Style Sheet Documentation. You can customize your own QProgressBar, and add your own setProgress() function which should update the value property. You could modify the image background, the border, margins... depending of the value of the current value.
See QSS examples for more detail: Example Style Sheet

Related

How to add a myOwn-background image to QPlainTextEdit?

For example, if you create a simple plaintextedit, the background is just white. How do I change white background with my own image?
In design edit, you can set the styleSheet in properties of QWidget. In c++ code you can set the background using QSS, for example, setting
‍‍‍‍background-image: URL("path/image.png");:
myWidget->setStyleSheet("background-image: URL('path/image.png')");

Set Image as Background and Text on Top of it in qlabel

I have a PNG file with 45x45 ratio
I have Qlabel with 270x30 Pixel ratio
what I want is to insert PNG file as background and Text on it dynamilaclly.
Text length may change from large to small and vise versa,
accorindly our image changes and fit the text inside the images its mean flexible image according to the text
QPixmap pixmapTarget = QPixmap(":/.png");
pixmapTarget = pixmapTarget.scaled(250, 27, Qt::IgnoreAspectRatio , Qt::SmoothTransformation);
ui->lable_1->setIcon(pixmapTarget);
but dont to insert text in the image and how to get flexible thing accoudning to the text.
A QLabel can contain either a text or an image. Not both at same time. If you want to have an image as a background to a text, you will need to either use a QTextView and setup your text and background image as rich text, overlay two QLabel instances on top of each other with the image being the bottom one, or implement your own custom QWidget. The latter can be done in a variety of ways, including subclassing QLabel to in paintEvent first render the background image (see QPainter's documentation on how to draw a QImage or better, a QPixmap) and then call the base implementation of paintEvent to render the text.

Set background color for QTabBar beyond tabs?

Simple as the question title, I have a QTabWidget and I wanted to set the background color for the QTabBar area, and this is how I do it:
ViewTabs->tabBar()->setStyleSheet("background-color: rgb(85,85,85)");
I expected this to set the back ground for the whole bar, but instead it sets the background on tabs only as in the attached picture.
How do I make the background color take effect even beyond the tabs? I'm using QT 5.7 with C++.
You can try to change the background color manually in the UI interface by clicking on "palette" in the proprieties.
It's easier to handle colors this way.

Interactively editing an existing rectangle on a QPixmap?

I'm trying to creat a Dicom GUI Toolkit where the user selects some dicom images and the image of first dicom image from the selected ones will be shown. Then the user clicks on the image and the image pops out with bigger image window. In this shown bigger image, the image will consist of a red colored rectangle that contains necessary regions of the Dicom image while the unnecessary region is outside the rectangle. The user should then have the option to change the rectangle by mouse.
Until now, I have been able to show the big dicom image with the rectangle in it using QLabel which is by the following code snippets.
void MainWindow::showBigImage()
{
QPixmap bigimage;
bigimage.load(imageName.c_str());
QPainter painter(&bigimage);
painter.setPen(Qt::red);
QRectF rect(xmin, ymin, xmax, ymax);
painter.drawRect(rect);
QSize bigsize = ui->bigImageLabel->size();
ui->bigImageLabel->setPixmap(bigimage.scaled(bigsize, Qt::IgnoreAspectRatio, Qt::FastTransformation));
ui->bigImageLabel->show();
}
and the big image on the app looks like the following:
Can you please suggest me how I should now make the rectangle editable by the user where the user can set the existing red rectangle as per his or her wish?
I also tried similar thing using QGraphicsView and QGraphicsScene with the following code:
void MainWindow::showBigImage()
{
QGraphicsScene* scene = new QGraphicsScene;
scene->addPixmap(bigimage);
ui->bigImageView->setScene(scene);
ui->bigImageView->show();
}
And this code gives me the following look:
As you can see, I could not fit the image to the boundaries of QGraphicsView, could you suggest me how to do it? Could you also suggest me how to add the red rectangle(that I showed in the example using QLabel) on the QGraphicsView without adding the rectangle on the QPixmap?
In order to get the red selection rectangle, Qt provides the class QRubberBand. The docs state:
The QRubberBand class provides a rectangle or line that can indicate a selection or a boundary.
By subclassing the image object and implementing the mouse handling functions, to create the rubber band on mousePressEvent, update its position on mouseMoveEvent and grab its final rect on mouseReleaseEvent, the QRubberBand will simplify the problem.
If you want the QRubberBand to show all the time, just create it when you display the enlarged image and don't hide it on releasing the mouse button.
As for displaying the image in the QGraphicsView, the code you displayed doesn't set the geometry of the QGraphicsScene and QGraphicsView, so you're seeing a border. If you don't want that, you should set them accordingly. Also note that QGraphicsView has a function fitInView, which you could use, after having retrieved an area from the QRubberBand, in order to zoom into the selected area.

Adding/resizing a background image to centralWidget in Qt

I'm new to Qt. I searched for my question on multiple sites, but I couldn't find an answer. How can I add an image to centralWidget?
I tried:
MainWindow w;
w.centralWidget()->setStyleSheet("image: url(image)");
it worked fine but the image isn't stretched for the entire window/widget. How can I resize the image through setStyleSheet?
I want to display an image in the background and not the gray color, when the application opens. I tried changing the color. That worked, but it doesn't look good with buttons and labels.
If you want it to stretch for the entire widget use background-image, but I'm guessing what you probably want is an image that expands in one direction, either vertically or horizontally, in that case use background-position to fix it to one of the borders of your widget:
image: url(:/path/to/image);
background-position: bottom left;