![]() |
[QT] EasyPaint help
Hello,
I am modifying EasyPaint to practice on different aspects of Qt, and I am trying to add a zoom slider function onto the status bar, I got it to work but there is a bug that I can't figure out.. Basically, the zoom doesn't work properly.. If someone can help me with this problem I will definitely appreciate it! <3 This is the code that I've added to mainwindow.h (in 'private slots'): Code:
void zoomSlider(int level); Code:
QSlider *zoomSliderBar = new QSlider(Qt::Horizontal, this); Code:
void MainWindow::zoomSlider(int level) // Zoom Slider Bar Function |
Re: [QT] EasyPaint help
What I mean by zoom not working properly, it zooms okay the first time you use the slider bar, then it just goes crazy everytime I try to use the slider (as in it zooms in and out but not in the order that it suppose to)...
|
Re: [QT] EasyPaint help
I would start by adding a qDebug in your zoomSlider method to see the actual values. Another thing I would do is replace the if-else ladder with a switch or, better still, with something like zoom(level * 0.5).
|
Re: [QT] EasyPaint help
Hello pichlo, thank you for replying back to me.. I'm not going to lie to you, I'm a beginner when it comes to Qt, so please excuse my noobness, but I tried using the qDebug but I am not even sure if I'm doing that correctly either (even when I read about it a bit online).. and when you say zoom(level * 0.5), what do you mean by that?
Did you mean something like this? Code:
void MainWindow::zoomSlider(int level) // Zoom Slider Bar Function I noticed that also clicking on a certain level rather than sliding the bar it directly either goes to the min or the max.. |
Re: [QT] EasyPaint help
Okay, so it kind of works now, but not exactly how it should either..
Here's my code for it so far: Code:
void MainWindow::zoomSlider(int level) // Zoom Slider Bar Function |
Re: [QT] EasyPaint help
Quote:
Quote:
You will only see the qDebug output if you launch your program from the command line, I may have forgotten to mention tht little fact. Quote:
0 -> 0.25The first thing that stands out is that with the exception of the first case, the mapped number is always 0.5 times the value of the parameter 'level'. In other words, level*0.5. Here is what I meant in code. Either... Code:
void MainWindow::zoomSlider(int level) // Zoom Slider Bar Function ...or... Code:
void MainWindow::zoomSlider(int level) // Zoom Slider Bar Function Quote:
|
Re: [QT] EasyPaint help
Quote:
And it seems on every tick the slider uses the correct "level", but the image isn't being resized like how it's suppose to.. :/ I'm going to upload the exe so you can see what I'm talking about.. EDIT: Here it is: http://dl.farahfa.com/tmp/EasyPaint |
Re: [QT] EasyPaint help
Sorry, I am a bit short on time but even if I were not, I am not going to run a random exe. No offence intended, just a personal policy.
However, to expand on this... Quote:
Here is an excellent example of a simple image zooming code, straight from the creators of Qt: http://qt-project.org/doc/qt-4.8/wid...ageviewer.html It might be a good idea to have a read through that article. It is quite long and a bit fragmented (it never shows the whole code), so to fully comprehend it you may need to read it front to end. It may not fit your specifications exactly but it may give you some inspiration. |
Re: [QT] EasyPaint help
Quote:
Either way, I really want to thank you for all your help! :D <3 |
Re: [QT] EasyPaint help
I had a look the EasyPaint code, and the existing zoom implementations call both zoomImage() and setZoomFactor(), so there is no problem there (see https://github.com/Gr1N/EasyPaint/bl....cpp#L641-L662).
I think you are setting the zoom factor incorrectly. The zoom values are not meant to be absolute, but relative to the previous value. Therefore, in your implementation, the result will differ depending on where you start from. For example, changing the slider value from 4 to 1 will produce a different result than moving from 2 to 1, and moving from n to 2 will not change the zoom at all. What you need to do is store the previous value of the slider, so when the value changes, you can calculate the correct zoom factor relative to the previous value: Code:
void MainWindow::zoomSlider(int level) { |
All times are GMT. The time now is 00:46. |
vBulletin® Version 3.8.8