In Qt I used the following method to load images and set them as the background of QLabels:
QPixmap *pixmap= new QPixmap("home\\Images\\circle.png");
ui->cell11_Image->setPixmap(*pixmap);
ui->cell11_Image->setMask(pixmap->mask());
ui->cell11_Image->show();
delete(pixmap);
With the following result
The thing is: the images are in grayscale. However, here is one of the images
Does anyone know what is going on?
I think your label or one of parent widget is disable. Try to enable and check.
Related
I am trying to set the background image of the mainwindow through setStyleSheet() but this also applies the image to its children including textbrowsers and TextEdit. How can I accomplish this without doing so?
Try to add What you have tried so far,with out that we cant help.
Try the below one
setStyleSheet("MainWindow {background-image:url(:/files/MainPic/Technology-Banner1.jpg)}");
I want to take a qml I created in the QTCreator and transform it to a bmp image.
what I want in the bmp image is just the items I created.
I read about grabWindow but this is not realy what I want because it takes a snapshot of the screen and not creating bmp image with only the items in the qml.
Thanks
From QML:
youritem.grabToImage(function(result) {
result.saveToFile("something.bmp");
});
Although a bmp image is a bad idea, those things are huge. png is the best candidate for QML stuff, which is usually more "vector-y".
I have an windows app which contains some dialogs. the dialogs have been built using mfc. I am drawing some images (.png) on every dialog using CImage::Draw() method. I want to mention that I am not using any picture contol on the dialog to render these images instead I am loading them at runtime using some handle.till this everything is ok. now when the image is loaded the background of those images are coming as white. the images in the resource file does not have the white background. my question is how to change the background of these images while drawing them on the dialog? I want the background of the image similar to the color of default dialog which i am using.
One more question the .png images are not rendering well(the images are scattered) in the dialogs of windows server 2008 R2 machine. what could be the possible remedy for this?
any help will be appreciated.
Your PNG images are obviously not 32-bit. You need an alpha channel and a transparent background. Open your images in e.g. Paint.NET. I bet your background is white there too! Regarding the image quality, are you stretching your images on draw?
Edit: For 8-bit imagers, I believe a call to SetTransparentColor is required. For 32-bit images, perhaps this function will do: TransparentBlt
I may be misunderstanding how to do this, hopefully somebody can clarify.
I have placed a QLabel on my main window from inside Qt Designer. Currently, it just displays the letters "TextLabel" when I run the program.
I have a line edit where I type in the path to an image, which then loads the image as a QImage into memory (I have this working).
Finally, I want to display this QImage. I was told this can be done by QLabels. I have done the following, but nothing is happening:
ui.input_label->setPixmap(QPixmap::fromImage(my_qimage));
Why is nothing happening? How can I display this image?
If you are sure the image file is ok but then the problem is probably with loading the file into the QImage. If you are calling QImage::load(), you are probably getting a return value of false.
All,
I must have a fundamental neuron missing, but I cannot get a simple program to load a PNG file and display it in a window. I'm not sure if it is a QPixmap, a QPicture, or what. All of the samples in the QTCreator are a bit more than I need right now. Baby steps...
I can get the window to display, and the program doesn't barf when I try to load the PNG, but it never gets displayed.
If someone would post a simple program to load a PNG from a file and display it, it would greatly appreciated. (I know, asking a lot, but...).
Thanks!
:bp:
this example is minimal: http://doc.trolltech.com/4.6/widgets-imageviewer.html
You will want to have a look at the function ImageViewer::open():
Build a QImage object from a filename;
Convert your QImage to a QPixmap with QPixmap::fromImage();
Put your QPixmap in a QLabel with QLabel::setPixmap().
The QImage object will automatically chose an appropriate reader according to the format of the image it detects in step 1.