![]() ![]() ![]() In the constructor we first create the QLabel displaying the screenshot preview. QuitScreenshotButton - >setShortcut( Qt ::CTRL | Qt ::Key_Q) Ĭonnect(quitScreenshotButton, & QPushButton ::clicked, this, & QWidget ::close) īuttonsLayout - >addWidget(quitScreenshotButton) QPushButton *quitScreenshotButton = new QPushButton(tr( "Quit"), this) QPushButton *saveScreenshotButton = new QPushButton(tr( "Save Screenshot"), this) Ĭonnect(saveScreenshotButton, & QPushButton ::clicked, this, &Screenshot ::saveScreenshot) īuttonsLayout - >addWidget(saveScreenshotButton) NewScreenshotButton = new QPushButton(tr( "New Screenshot"), this) Ĭonnect(newScreenshotButton, & QPushButton ::clicked, this, &Screenshot ::newScreenshot) īuttonsLayout - >addWidget(newScreenshotButton) QHBoxLayout *buttonsLayout = new QHBoxLayout MainLayout - >addWidget(optionsGroupBox) OptionsGroupBoxLayout - >addWidget(hideThisWindowCheckBox, 1, 0, 1, 2) OptionsGroupBoxLayout - >addWidget(delaySpinBox, 0, 1) OptionsGroupBoxLayout - >addWidget( new QLabel(tr( "Screenshot Delay:"), this), 0, 0) QGridLayout *optionsGroupBoxLayout = new QGridLayout(optionsGroupBox) ![]() HideThisWindowCheckBox = new QCheckBox(tr( "Hide This Window"), optionsGroupBox) QGroupBox *optionsGroupBox = new QGroupBox(tr( "Options"), this) ĭelaySpinBox = new QSpinBox(optionsGroupBox) Ĭonnect(delaySpinBox, & QSpinBox ::valueChanged, this, &Screenshot ::updateCheckBox) MainLayout - >addWidget(screenshotLabel) QVBoxLayout *mainLayout = new QVBoxLayout( this) ScreenshotLabel - >setMinimumSize(screenGeometry. ScreenshotLabel - >setAlignment( Qt ::AlignCenter) Ĭonst QRect screenGeometry = screen() - >geometry() ScreenshotLabel - >setSizePolicy( QSizePolicy ::Expanding, QSizePolicy ::Expanding) The reason is that when we display the preview of the screenshot, we need to scale its pixmap, storing the original we make sure that no data are lost in that process. In addition we need to store the screenshot's original pixmap. We also declare the private function updateScreenshotLabel() which is called whenever a new screenshot is taken or when a resize event changes the size of the screenshot preview label. The updateCheckBox() slot enables or disables the Hide This Window option.The shootScreen() slot takes the screenshot.The saveScreenshot() slot saves the last screenshot.The newScreenshot() slot prepares a new screenshot.We also need several private slots to facilitate the options: We reimplement the QWidget::resizeEvent() function to make sure that the preview of the screenshot scales properly when the user resizes the application widget. It displays the application options and a preview of the screenshot. The Screenshot class inherits QWidget and is the application's main widget. Void resizeEvent( QResizeEvent *event) override ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |