Last active
December 12, 2020 18:36
-
-
Save Riateche/7258849 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#------------------------------------------------- | |
# | |
# Project created by QtCreator 2013-09-26T13:32:37 | |
# | |
#------------------------------------------------- | |
QT += core gui network testlib | |
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | |
TARGET = untitled | |
TEMPLATE = app | |
SOURCES += main.cpp\ | |
MainWindow.cpp | |
HEADERS += MainWindow.h | |
FORMS += MainWindow.ui |
This file contains hidden or 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 "MainWindow.h" | |
#include <QApplication> | |
int main(int argc, char *argv[]) { | |
QApplication app(argc, argv); | |
MainWindow w; | |
w.show(); | |
return app.exec(); | |
} |
This file contains hidden or 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 "MainWindow.h" | |
#include "ui_MainWindow.h" | |
#include <QDebug> | |
#include <QMouseEvent> | |
#include "windows.h" | |
#include <QWindow> | |
MainWindow::MainWindow(QWidget *parent) : | |
QMainWindow(parent), | |
ui(new Ui::MainWindow) | |
{ | |
ui->setupUi(this); | |
show(); | |
HWND hwnd = reinterpret_cast<HWND>(effectiveWinId()); | |
LONG lStyle = GetWindowLong(hwnd, GWL_STYLE); | |
lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU); | |
SetWindowLong(hwnd, GWL_STYLE, lStyle); | |
setWindowFlags(windowFlags() | Qt::FramelessWindowHint); | |
windowHandle()->reportContentOrientationChange(Qt::PrimaryOrientation); | |
} | |
MainWindow::~MainWindow() { | |
delete ui; | |
} | |
void MainWindow::mousePressEvent(QMouseEvent *e) { | |
if (!isMaximized() && e->button() == Qt::LeftButton && ui->title->geometry().contains(e->pos())) { | |
window_drag_start_pos = e->pos(); | |
} | |
} | |
void MainWindow::mouseReleaseEvent(QMouseEvent *e) { | |
window_drag_start_pos = QPoint(0, 0); | |
} | |
void MainWindow::mouseMoveEvent(QMouseEvent *e) { | |
if (!window_drag_start_pos.isNull()) { | |
move(pos() + e->pos() - window_drag_start_pos); | |
} | |
} | |
void MainWindow::on_minimize_clicked() { | |
showMinimized(); | |
} | |
void MainWindow::on_maximize_clicked() { | |
if (isMaximized()) { | |
showNormal(); | |
} else { | |
showMaximized(); | |
} | |
} |
This file contains hidden or 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 MAINWINDOW_H | |
#define MAINWINDOW_H | |
#include <QMainWindow> | |
#include <QStandardItemModel> | |
#include <QComboBox> | |
namespace Ui { | |
class MainWindow; | |
} | |
class MainWindow : public QMainWindow | |
{ | |
Q_OBJECT | |
public: | |
explicit MainWindow(QWidget *parent = 0); | |
~MainWindow(); | |
private: | |
Ui::MainWindow *ui; | |
QPoint window_drag_start_pos; | |
void mousePressEvent(QMouseEvent* e); | |
void mouseReleaseEvent(QMouseEvent* e); | |
void mouseMoveEvent(QMouseEvent* e); | |
private slots: | |
void on_minimize_clicked(); | |
void on_maximize_clicked(); | |
}; | |
#endif // MAINWINDOW_H |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<ui version="4.0"> | |
<class>MainWindow</class> | |
<widget class="QMainWindow" name="MainWindow"> | |
<property name="geometry"> | |
<rect> | |
<x>0</x> | |
<y>0</y> | |
<width>526</width> | |
<height>392</height> | |
</rect> | |
</property> | |
<property name="windowTitle"> | |
<string>MainWindow</string> | |
</property> | |
<widget class="QWidget" name="centralWidget"> | |
<layout class="QVBoxLayout" name="verticalLayout"> | |
<property name="margin"> | |
<number>0</number> | |
</property> | |
<item> | |
<layout class="QHBoxLayout" name="horizontalLayout"> | |
<item> | |
<widget class="QLabel" name="title"> | |
<property name="sizePolicy"> | |
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> | |
<horstretch>0</horstretch> | |
<verstretch>0</verstretch> | |
</sizepolicy> | |
</property> | |
<property name="text"> | |
<string>title</string> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="QPushButton" name="minimize"> | |
<property name="text"> | |
<string>minimize</string> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="QPushButton" name="maximize"> | |
<property name="text"> | |
<string>maximize</string> | |
</property> | |
</widget> | |
</item> | |
</layout> | |
</item> | |
<item> | |
<widget class="QTableView" name="tableView"/> | |
</item> | |
</layout> | |
</widget> | |
<widget class="QStatusBar" name="statusBar"/> | |
</widget> | |
<layoutdefault spacing="6" margin="11"/> | |
<resources/> | |
<connections/> | |
</ui> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment