mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-04 00:05:25 +08:00
qt 6.5.1 original
This commit is contained in:
@ -0,0 +1,50 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(basicgraphicslayouts LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/graphicsview/basicgraphicslayouts")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(basicgraphicslayouts
|
||||
layoutitem.cpp layoutitem.h
|
||||
main.cpp
|
||||
window.cpp window.h
|
||||
)
|
||||
|
||||
set_target_properties(basicgraphicslayouts PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(basicgraphicslayouts PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
# Resources:
|
||||
set(basicgraphicslayouts_resource_files
|
||||
"images/block.png"
|
||||
)
|
||||
|
||||
qt_add_resources(basicgraphicslayouts "basicgraphicslayouts"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
${basicgraphicslayouts_resource_files}
|
||||
)
|
||||
|
||||
install(TARGETS basicgraphicslayouts
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
@ -0,0 +1,12 @@
|
||||
QT += widgets
|
||||
|
||||
HEADERS = layoutitem.h \
|
||||
window.h
|
||||
SOURCES = layoutitem.cpp \
|
||||
main.cpp \
|
||||
window.cpp
|
||||
RESOURCES = basicgraphicslayouts.qrc
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/graphicsview/basicgraphicslayouts
|
||||
INSTALLS += target
|
@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource>
|
||||
<file>images/block.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
@ -0,0 +1,90 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include "layoutitem.h"
|
||||
|
||||
#include <QGradient>
|
||||
#include <QPainter>
|
||||
|
||||
//! [0]
|
||||
LayoutItem::LayoutItem(QGraphicsItem *parent)
|
||||
: QGraphicsLayoutItem(), QGraphicsItem(parent),
|
||||
m_pix(QPixmap(QLatin1String(":/images/block.png")))
|
||||
{
|
||||
setGraphicsItem(this);
|
||||
}
|
||||
//! [0]
|
||||
|
||||
//! [1]
|
||||
void LayoutItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
Q_UNUSED(option);
|
||||
|
||||
QRectF frame(QPointF(0, 0), geometry().size());
|
||||
const QSize pmSize = m_pix.size();
|
||||
QGradientStops stops;
|
||||
//! [1]
|
||||
|
||||
//! [2]
|
||||
// paint a background rect (with gradient)
|
||||
QLinearGradient gradient(frame.topLeft(), frame.topLeft() + QPointF(200,200));
|
||||
stops << QGradientStop(0.0, QColor(60, 60, 60));
|
||||
stops << QGradientStop(frame.height() / 2 / frame.height(), QColor(102, 176, 54));
|
||||
|
||||
//stops << QGradientStop(((frame.height() + h)/2 )/frame.height(), QColor(157, 195, 55));
|
||||
stops << QGradientStop(1.0, QColor(215, 215, 215));
|
||||
gradient.setStops(stops);
|
||||
painter->setBrush(QBrush(gradient));
|
||||
painter->drawRoundedRect(frame, 10.0, 10.0);
|
||||
|
||||
// paint a rect around the pixmap (with gradient)
|
||||
QPointF pixpos = frame.center() - (QPointF(pmSize.width(), pmSize.height()) / 2);
|
||||
QRectF innerFrame(pixpos, pmSize);
|
||||
innerFrame.adjust(-4, -4, 4, 4);
|
||||
gradient.setStart(innerFrame.topLeft());
|
||||
gradient.setFinalStop(innerFrame.bottomRight());
|
||||
stops.clear();
|
||||
stops << QGradientStop(0.0, QColor(215, 255, 200));
|
||||
stops << QGradientStop(0.5, QColor(102, 176, 54));
|
||||
stops << QGradientStop(1.0, QColor(0, 0, 0));
|
||||
gradient.setStops(stops);
|
||||
painter->setBrush(QBrush(gradient));
|
||||
painter->drawRoundedRect(innerFrame, 10.0, 10.0);
|
||||
painter->drawPixmap(pixpos, m_pix);
|
||||
}
|
||||
//! [2]
|
||||
|
||||
//! [3]
|
||||
QRectF LayoutItem::boundingRect() const
|
||||
{
|
||||
return QRectF(QPointF(0, 0), geometry().size());
|
||||
}
|
||||
//! [3]
|
||||
|
||||
//! [4]
|
||||
void LayoutItem::setGeometry(const QRectF &geom)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
QGraphicsLayoutItem::setGeometry(geom);
|
||||
setPos(geom.topLeft());
|
||||
}
|
||||
//! [4]
|
||||
|
||||
//! [5]
|
||||
QSizeF LayoutItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
|
||||
{
|
||||
switch (which) {
|
||||
case Qt::MinimumSize:
|
||||
case Qt::PreferredSize:
|
||||
// Do not allow a size smaller than the pixmap with two frames around it.
|
||||
return m_pix.size() + QSize(12, 12);
|
||||
case Qt::MaximumSize:
|
||||
return QSizeF(1000,1000);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return constraint;
|
||||
}
|
||||
//! [5]
|
@ -0,0 +1,30 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#ifndef LAYOUTITEM_H
|
||||
#define LAYOUTITEM_H
|
||||
|
||||
#include <QGraphicsLayoutItem>
|
||||
#include <QGraphicsItem>
|
||||
#include <QPixmap>
|
||||
|
||||
//! [0]
|
||||
class LayoutItem : public QGraphicsLayoutItem, public QGraphicsItem
|
||||
{
|
||||
public:
|
||||
LayoutItem(QGraphicsItem *parent = nullptr);
|
||||
|
||||
// Inherited from QGraphicsLayoutItem
|
||||
void setGeometry(const QRectF &geom) override;
|
||||
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override;
|
||||
|
||||
// Inherited from QGraphicsItem
|
||||
QRectF boundingRect() const override;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
|
||||
|
||||
private:
|
||||
QPixmap m_pix;
|
||||
};
|
||||
//! [0]
|
||||
|
||||
#endif // LAYOUTITEM_H
|
22
examples/widgets/graphicsview/basicgraphicslayouts/main.cpp
Normal file
22
examples/widgets/graphicsview/basicgraphicslayouts/main.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include "window.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QGraphicsView>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
QGraphicsScene scene;
|
||||
|
||||
Window *window = new Window;
|
||||
scene.addItem(window);
|
||||
QGraphicsView view(&scene);
|
||||
view.resize(600, 600);
|
||||
view.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include "window.h"
|
||||
#include "layoutitem.h"
|
||||
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <QGraphicsGridLayout>
|
||||
|
||||
Window::Window(QGraphicsWidget *parent) : QGraphicsWidget(parent, Qt::Window)
|
||||
{
|
||||
//! [0]
|
||||
QGraphicsLinearLayout *windowLayout = new QGraphicsLinearLayout(Qt::Vertical);
|
||||
QGraphicsLinearLayout *linear = new QGraphicsLinearLayout(windowLayout);
|
||||
LayoutItem *item = new LayoutItem;
|
||||
linear->addItem(item);
|
||||
linear->setStretchFactor(item, 1);
|
||||
//! [0]
|
||||
|
||||
//! [1]
|
||||
item = new LayoutItem;
|
||||
linear->addItem(item);
|
||||
linear->setStretchFactor(item, 3);
|
||||
windowLayout->addItem(linear);
|
||||
//! [1]
|
||||
|
||||
//! [2]
|
||||
QGraphicsGridLayout *grid = new QGraphicsGridLayout(windowLayout);
|
||||
item = new LayoutItem;
|
||||
grid->addItem(item, 0, 0, 4, 1);
|
||||
item = new LayoutItem;
|
||||
item->setMaximumHeight(item->minimumHeight());
|
||||
grid->addItem(item, 0, 1, 2, 1, Qt::AlignVCenter);
|
||||
item = new LayoutItem;
|
||||
item->setMaximumHeight(item->minimumHeight());
|
||||
grid->addItem(item, 2, 1, 2, 1, Qt::AlignVCenter);
|
||||
item = new LayoutItem;
|
||||
grid->addItem(item, 0, 2);
|
||||
item = new LayoutItem;
|
||||
grid->addItem(item, 1, 2);
|
||||
item = new LayoutItem;
|
||||
grid->addItem(item, 2, 2);
|
||||
item = new LayoutItem;
|
||||
grid->addItem(item, 3, 2);
|
||||
windowLayout->addItem(grid);
|
||||
//! [2]
|
||||
|
||||
//! [3]
|
||||
setLayout(windowLayout);
|
||||
setWindowTitle(tr("Basic Graphics Layouts Example"));
|
||||
//! [3]
|
||||
|
||||
}
|
20
examples/widgets/graphicsview/basicgraphicslayouts/window.h
Normal file
20
examples/widgets/graphicsview/basicgraphicslayouts/window.h
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#ifndef WINDOW_H
|
||||
#define WINDOW_H
|
||||
|
||||
#include <QGraphicsWidget>
|
||||
|
||||
//! [0]
|
||||
class Window : public QGraphicsWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Window(QGraphicsWidget *parent = nullptr);
|
||||
|
||||
};
|
||||
//! [0]
|
||||
|
||||
#endif //WINDOW_H
|
||||
|
Reference in New Issue
Block a user