Unsolved Cannot set stylesheet within method body, but can inside constructor
-
Hi,
Are you sure the pixmap you are setting is valid ?
-
I'm fairly certain it's valid. In debug mode the width, height, pixel depth all that get set. The creation returns a bool right? I'll add my code here while I investigate that.
There are some objects from a library in there, but I check that the QImage is created with the right properties. I also save the QImage to disk and it was what I expected, so I'm pretty sure the QImage is fine.
-
Did you try to let QPixmap operate a format conversion ?
-
There is no change. I set the format to MonoOnly and nothing changed. If I load the Pixmap from data using any format it will break it as the incoming format is RAW which Qt cannot handle. Which is why I turned to loading directly from a Qimage even if it's slowler.
-
What exactly do you mean by RAW ?
-
Its just the pixel values there's no header. It's simply the width x height of pixels given as an unsigned char*. Either way it doesn't display the pixmap I just had more success loading it from an image than the raw data.
-
I'm not sure the problem is even with the pixmap. That's why I attempted to change the style sheet of the label in there too. The style sheet does not get changed despite the code executing. Whereas, if I change the stylesheet in the constructor that code works. So something beyond my understanding is going on here.
-
I would try with loading a known image from the disk.
-
I've attempted that as well. I placed the image in the directory with the ui files. Was that incorrect?
-
Hey, did you try not setting any format parameter (leaving it as auto) and see if it can show? Just
QPixmap::fromImage(qt_g_image)
And if you try to test with a image from the disk, better to load it by the full path, then it doesn't matter where you put it.
-
@Bonnie I'll try both of those tomorrow and let ya know how it goes.
-
Use the full path to the test image. If you use a relative path it won't work because your executable is not built in the same folder as your sources.
-
I think I figured out why the code doesn't work. The function calling this method is activated by a slot in my application. However, this slot is essentially a while(true) loop that doesn't stop acquiring pictures until I press the space bar. I just noticed while acquiring images none of the other buttons on my GUI are clickable, which makes sense since that loop is still running. I thought that Qt slots were asynchronous, but I guess I'm understanding something wrong?? If anyone has ideas as to how I can fix this because I can't simply throw the function in another thread of execution.
-
Ok I added QCoreApplication::processEvents(); into the blocking event and all of the buttons are unblocked; however, the pixmap still did not display so I guess that was not the issue.
-
Asynchronous does not mean that several threads are running in parallel. A while loop will always "block" the execution of the thread it runs in inside the body of the loop.
Did you check with the full path to a test image like I suggested ?
-
I fixed the issue. It turns out it was not fully Qt related. I did add a call to update() however.
-
What was the issue ?