Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdesigner_widget.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant reason:default
4
7#include "grid_p.h"
8
9#include <QtDesigner/abstractformwindow.h>
10#include <QtGui/qpainter.h>
11#include <QtWidgets/qstyle.h>
12#include <QtWidgets/qstyleoption.h>
13#include <QtGui/qevent.h>
14
16
17/* QDesignerDialog / QDesignerWidget are used to paint a grid on QDialog and QWidget main containers
18 * and container extension pages.
19 * The paint routines work as follows:
20 * We need to clean the background here (to make the parent grid disappear in case we are a container page
21 * and to make palette background settings take effect),
22 * which would normally break style sheets with background settings.
23 * So, we manually make the style paint after cleaning. On top comes the grid
24 * In addition, this code works around
25 * the QStyleSheetStyle setting Qt::WA_StyledBackground to false for subclasses of QWidget.
26 */
27
28QDesignerDialog::QDesignerDialog(QDesignerFormWindowInterface *fw, QWidget *parent) :
29 QDialog(parent),
30 m_formWindow(qobject_cast<qdesigner_internal::FormWindowBase*>(fw))
31{
32}
33
34void QDesignerDialog::paintEvent(QPaintEvent *e)
35{
36 QPainter p(this);
37 QStyleOption opt;
38 opt.initFrom(this);
39 p.fillRect(e->rect(), palette().brush(backgroundRole()));
40 style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
41 if (m_formWindow && m_formWindow->gridVisible())
42 m_formWindow->designerGrid().paint(p, this, e);
43}
44
45QDesignerWidget::QDesignerWidget(QDesignerFormWindowInterface* formWindow, QWidget *parent) :
46 QWidget(parent),
47 m_formWindow(qobject_cast<qdesigner_internal::FormWindowBase*>(formWindow))
48{
49}
50
51QDesignerWidget::~QDesignerWidget() = default;
52
53QDesignerFormWindowInterface* QDesignerWidget::formWindow() const
54{
55 return m_formWindow;
56}
57
58void QDesignerWidget::paintEvent(QPaintEvent *e)
59{
60 QPainter p(this);
61 QStyleOption opt;
62 opt.initFrom(this);
63 p.fillRect(e->rect(), palette().brush(backgroundRole()));
64 style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
65 if (m_formWindow && m_formWindow->gridVisible())
66 m_formWindow->designerGrid().paint(p, this, e);
67}
68
69QT_END_NAMESPACE
Combined button and popup list for selecting options.