Created
April 9, 2022 12:46
-
-
Save andr1972/317f6fa28e6d40b443645ee8b5509125 to your computer and use it in GitHub Desktop.
Start creating Qt compoenent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "dialog.h" | |
#include <QVBoxLayout> | |
#include <qxviewer.h> | |
#include <QLineEdit> | |
#include <QPushButton> | |
Dialog::Dialog() | |
{ | |
QVBoxLayout *mainLayout = new QVBoxLayout; | |
QxViewer *widget = new QxViewer; | |
//widget->setBaseSize(400,400); | |
QHBoxLayout *hLayout = new QHBoxLayout; | |
hLayout->addWidget(new QLineEdit); | |
hLayout->addWidget(new QPushButton); | |
mainLayout->addLayout(hLayout); | |
mainLayout->addWidget(widget); | |
//widget.show(); | |
setLayout(mainLayout); | |
mainLayout->setMargin(3); | |
resize(400,400); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef DIALOG_H | |
#define DIALOG_H | |
#include <QDialog> | |
class Dialog : public QDialog | |
{ | |
public: | |
Dialog(); | |
}; | |
#endif // DIALOG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "qxviewer.h" | |
#include <QApplication> | |
#include <dialog.h> | |
int main(int argc, char *argv[]) | |
{ | |
QApplication app(argc, argv); | |
Dialog dialog; | |
dialog.show(); | |
return app.exec(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "qxviewer.h" | |
#include <QPainter> | |
#include <QKeyEvent> | |
QxViewer::QxViewer(QWidget *parent) : | |
QWidget(parent) | |
{ | |
setWindowTitle(tr("Viewer")); | |
#if QT_CONFIG(cursor) | |
setCursor(Qt::IBeamCursor); | |
#endif | |
} | |
void QxViewer::paintEvent(QPaintEvent * /* event */) | |
{ | |
QPainter painter(this); | |
painter.fillRect(rect(), Qt::black); | |
painter.setPen(*(new QColor(255,34,255,255))); | |
painter.drawRect(15,15,100,100); | |
painter.setPen(Qt::white); | |
painter.drawText(rect(), Qt::AlignCenter, tr("Text on center")); | |
} | |
#if QT_CONFIG(wheelevent) | |
void QxViewer::wheelEvent(QWheelEvent *event) | |
{ | |
} | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef WIDGET_H | |
#define WIDGET_H | |
#include <QWidget> | |
#include <QScrollBar> | |
class QxViewer : public QWidget | |
{ | |
Q_OBJECT | |
QScrollBar vscroll; | |
QScrollBar hscroll; | |
public: | |
explicit QxViewer(QWidget *parent = nullptr); | |
protected: | |
void paintEvent(QPaintEvent *event) override; | |
// void resizeEvent(QResizeEvent *event) override; | |
// void keyPressEvent(QKeyEvent *event) override; | |
#if QT_CONFIG(wheelevent) | |
void wheelEvent(QWheelEvent *event) override; | |
#endif | |
// void mousePressEvent(QMouseEvent *event) override; | |
// void mouseMoveEvent(QMouseEvent *event) override; | |
// void mouseReleaseEvent(QMouseEvent *event) override; | |
private: | |
// void scroll(int deltaX, int deltaY); | |
}; | |
#endif // WIDGET_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment