Labs for QT in Education
Anyone has a proper solution to the Lab2 for L5 and L6. I have a little problem, im new to
QT Qt and i’m trying to incorporate some of these Labs into an intro. gui course. I’m not familiar with Q_PROPERTY and a section of the Lab deals with adding set and get in Q_PROPERTY for Value, minimum and maximum. How do I check if they are within the specified range?
I stuck on the part of the Lab 2 -custom widgets, graphics view and canvas. The section with Designing the API, it says
Repeat the process described for the value property to add the minimum and maximum properties of type QSize. Modify the setValue() slot to make sure the value always is within the valid range and implement setters of the new properties in such a way that they too make sure the value is constrained to the new range.
What i don’t understand is if we add Q_PROPERTY to minimum and maximum of type QSize and try to use qBound() it gives me error. How do I check that the value is within range. Can you use QSize with qBound()? any help on this section of the Lab would be welcomed… thanks.
Edit: layout fixes; Andre
qBound() for QSize is not defined because it is not easily determined whether (20,10) is larger than (10, 20).
You need to do the comparison dimension by dimension like that:
or make use of QSize::boundedTo() and QSize::expandedTo():
Of course you could also just define qBound() for QSize:
- return curr.boundedTo(max).expandedTo(min);
Hope that helps, good luck with your lab :)