parent
1cd1b0cc2b
commit
236ac54faf
|
@ -7,9 +7,38 @@
|
|||
#include "framelessquickhelper.h"
|
||||
#include <QQmlApplicationEngine>
|
||||
#endif
|
||||
#include <QPainter>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
class FramelessWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY_MOVE(FramelessWidget)
|
||||
|
||||
public:
|
||||
explicit FramelessWidget(QWidget *parent = nullptr) : QWidget(parent) {}
|
||||
~FramelessWidget() override = default;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override
|
||||
{
|
||||
QWidget::paintEvent(event);
|
||||
QPainter painter(this);
|
||||
painter.save();
|
||||
painter.setPen(isActiveWindow() ? borderColor_active : borderColor_inactive);
|
||||
painter.drawLine(0, 0, width(), 0);
|
||||
painter.drawLine(0, height(), width(), height());
|
||||
painter.drawLine(0, 0, 0, height());
|
||||
painter.drawLine(width(), 0, width(), height());
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
private:
|
||||
const QColor borderColor_active = {"#707070"};
|
||||
const QColor borderColor_inactive = {"#aaaaaa"};
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// High DPI scaling is enabled by default from Qt 6
|
||||
|
@ -41,8 +70,8 @@ int main(int argc, char *argv[])
|
|||
QApplication application(argc, argv);
|
||||
|
||||
// Qt Widgets example:
|
||||
QWidget widget;
|
||||
widget.setContentsMargins(0, 0, 0, 0);
|
||||
FramelessWidget widget;
|
||||
widget.setContentsMargins(2, 2, 2, 2);
|
||||
QLabel *label = new QLabel;
|
||||
QObject::connect(&widget, &QWidget::windowTitleChanged, label, &QLabel::setText);
|
||||
QPushButton *minimizeButton = new QPushButton;
|
||||
|
@ -113,3 +142,5 @@ int main(int argc, char *argv[])
|
|||
|
||||
return QApplication::exec();
|
||||
}
|
||||
|
||||
#include "main_windows.moc"
|
||||
|
|
|
@ -13,13 +13,23 @@ Window {
|
|||
id: framelessHelper
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
border.color: Qt.application.state === Qt.ApplicationActive ? "#707070" : "#aaaaaa"
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: titleBar
|
||||
height: framelessHelper.titleBarHeight
|
||||
color: "white"
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors {
|
||||
top: parent.top
|
||||
topMargin: 1
|
||||
left: parent.left
|
||||
leftMargin: 1
|
||||
right: parent.right
|
||||
rightMargin: 1
|
||||
}
|
||||
|
||||
Text {
|
||||
id: titleBarText
|
||||
|
@ -69,10 +79,15 @@ Window {
|
|||
Rectangle {
|
||||
id: content
|
||||
color: "#f0f0f0"
|
||||
anchors.top: titleBar.bottom
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors {
|
||||
top: titleBar.bottom
|
||||
bottom: parent.bottom
|
||||
bottomMargin: 1
|
||||
left: parent.left
|
||||
leftMargin: 1
|
||||
right: parent.right
|
||||
rightMargin: 1
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: framelessHelper.removeWindowFrame()
|
||||
|
|
Loading…
Reference in New Issue