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
6#include "grid_p.h"
7
8#include <QtDesigner/abstractformwindow.h>
9#include <QtGui/qpainter.h>
10#include <QtWidgets/qstyle.h>
11#include <QtWidgets/qstyleoption.h>
12#include <QtGui/qevent.h>
13
15
16/* QDesignerDialog / QDesignerWidget are used to paint a grid on QDialog and QWidget main containers
17 * and container extension pages.
18 * The paint routines work as follows:
19 * We need to clean the background here (to make the parent grid disappear in case we are a container page
20 * and to make palette background settings take effect),
21 * which would normally break style sheets with background settings.
22 * So, we manually make the style paint after cleaning. On top comes the grid
23 * In addition, this code works around
24 * the QStyleSheetStyle setting Qt::WA_StyledBackground to false for subclasses of QWidget.
25 */
26
27QDesignerDialog::QDesignerDialog(QDesignerFormWindowInterface *fw, QWidget *parent) :
28 QDialog(parent),
29 m_formWindow(qobject_cast<qdesigner_internal::FormWindowBase*>(fw))
30{
31}
32
33void QDesignerDialog::paintEvent(QPaintEvent *e)
34{
35 QPainter p(this);
36 QStyleOption opt;
37 opt.initFrom(this);
38 p.fillRect(e->rect(), palette().brush(backgroundRole()));
39 style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
40 if (m_formWindow && m_formWindow->gridVisible())
41 m_formWindow->designerGrid().paint(p, this, e);
42}
43
44QDesignerWidget::QDesignerWidget(QDesignerFormWindowInterface* formWindow, QWidget *parent) :
45 QWidget(parent),
46 m_formWindow(qobject_cast<qdesigner_internal::FormWindowBase*>(formWindow))
47{
48}
49
50QDesignerWidget::~QDesignerWidget() = default;
51
52QDesignerFormWindowInterface* QDesignerWidget::formWindow() const
53{
54 return m_formWindow;
55}
56
57void QDesignerWidget::paintEvent(QPaintEvent *e)
58{
59 QPainter p(this);
60 QStyleOption opt;
61 opt.initFrom(this);
62 p.fillRect(e->rect(), palette().brush(backgroundRole()));
63 style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
64 if (m_formWindow && m_formWindow->gridVisible())
65 m_formWindow->designerGrid().paint(p, this, e);
66}
67
68QT_END_NAMESPACE
Combined button and popup list for selecting options.