![]() ![]() ![]() We ensure that the label will scale its contents to fill all available space, to enable the image to scale properly when zooming. Otherwise, the default size polizy ( preferred) will make scroll bars appear when the scroll area becomes smaller than the label's minimum size hint. We set imageLabel's size policy to ignored, making the users able to scale the image to whatever size they want when the Fit to Window option is turned on. In the constructor we first create the label and the scroll area. ScrollArea->setBackgroundRole(QPalette::Dark) ![]() ImageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored) ImageLabel->setBackgroundRole(QPalette::Base) ImageViewer Class Implementation ImageViewer::ImageViewer() In turn, scaleImage() uses adjustScrollBar() to preserve the focal point after scaling an image. The zoom slots use scaleImage() to perform the zooming. #IMAGEVIEWER 4.0 UPDATE#We use the updateActions() function to update the menu entries when a new image is loaded, or when the Fit to Window option is toggled. We use createActions() and createMenus() when constructing the ImageViewer widget. In addition we create four private functions. We reimplement the constructor, and create several private slots to facilitate the menu entries. The ImageViewer class inherits from QMainWindow. Void adjustScrollBar(QScrollBar *scrollBar, double factor) ![]() ImageViewer Class Definition class ImageViewer : public QMainWindow In addition the Help menu provides the users with information about the ImageViewer example in particular, and about Qt in general. Fit to Window - Stretch the image to occupy the entire window.Normal Size - Show the image at its original size.Once an image is loaded, the View menu allows the users to: The File menu gives the user the possibility to: With the ImageViewer application, the users can view an image of their choice. #IMAGEVIEWER 4.0 HOW TO#In addition the example shows how to use QPainter to print an image. The example demonstrates how QLabel's ability to scale its contents ( QLabel::scaledContents), and QScrollArea's ability to automatically resize its contents ( QScrollArea::widgetResizable), can be used to implement zooming and scaling features. If the child widget exceeds the size of the frame, QScrollArea automatically provides scroll bars. QScrollArea provides a scrolling view around another widget. QLabel is typically used for displaying text, but it can also display an image. #IMAGEVIEWER 4.0 SOFTWARE#IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.The example shows how to combine QLabel and QScrollArea to display an image. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. #IMAGEVIEWER 4.0 FREE#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |