How do I set a background image to mainwindow? - c++

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)}");

Related

Change QwtPlot background while using dark mode gui?

When I dissable dark mode which is provided via BreezeStyleSheet:
https://github.com/Alexhuszagh/BreezeStyleSheets
it works (I can change background with set canvas palette to whatever I want and then attach it to QwtPlot). But when I use style sheet it seems almost impossible to set it. Have anybody some ideas how to fix this issue ?
For custom widget based on QwtPlot it will be:
this->canvas()->setStyleSheet("background-color: black;border: none;");
in constructor.

Qt - QPixmap converts png to gray scale?

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.

QApplication::processEvents not working in Windows

I am working on a project that presents live data acquired in real-time using the QCustomPlot plug-in for Qt. The display has a black background color, and the multiple channels of data are colored differently. When taking a screenshot, we would like to make it printer-friendly, so the background is white and all data is black. I am thinking of a solution like this:
Change all colors the way I want by manipulating the pointers for the graphical objects
Grab the screenshot using QWidget::grab() to get a QPixmap
Change all the colors back to normal
This did not work at first, because the system could not change the colors in time for the screenshot to be taken. So I used a QApplication::processEvents(), and it all worked on my Mac.
However, it does not work on a Windows 7 (which is required). Any ideas what to do?
Code:
QSting fileLocation = "...";
toggleColors(false); //function to toggle the colors
QApplication::processEvents();
QPixmap shot = grab();
toggleColors(true);
shot.save(fileLocation, "png");
Again. It works on Mac, but not Windows.
Update 1. Content of toggleColors include:
if(enable)
ui->plot->setBackground(QBrush(Qt::black));
else
ui->plot->setBackground(QBrush(Qt::white));
ui->plot->repaint();
I also tried with ui->plot->update() instead.
I am not sure what is the problem on Windows specifically, but I recommend you calling QWidget::update() on the given widget. That forces the next update to re-render itself.
On the other hand, I'm not sure why toggleColors() didn't somehow cause that to happen.
Also, ensure that QWidget::setUpdatesEnabled(bool) wasn't set to "false."
It appears the problem lies with QCustomPlot. It was solved by performing a ui->plot->replot() which is specific to QCustomPlot and not QWidget.

GTK 3 transparent label with text placed over image

i need to create GTK GUI with image and transparent label (darker) that is placed over the image. The first problem is overlapping. I tried Gtk::Table and Gtk::Fixed container but it behaves strangely. The second problem is transparency. I would like to use CSS styles or transparent background image. Is there anybody who can help me posting some sources or examples? Thanks
You could subclass GtkWidget, or GtkDrawingArea since I think it will be faster than the altenatives. But you could use GtkOverlay, plus GtkImage and GtkLabel to acomplish what you're looking for.
gtk3-demo app that comes with Gtk+-3.0 give some examples of how to use GtkOverlay.
Maybe you could give a look to clutter-gtk ? You can do nice things with it.

How to update a QLabel to display a QImage

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.