⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qwidget.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  \i Qt::WA_WState_CompressKeys Compress keyboard events.  \i Qt::WA_WState_BlockUpdates Repaints and updates are disabled.  \i Qt::WA_WState_InPaintEvent Currently processing a paint event.  \i Qt::WA_WState_Reparented The widget has been reparented.  \i Qt::WA_WState_ConfigPending A configuration (resize/move) event is pending.  \i Qt::WA_WState_DND (Deprecated) The widget supports drag and drop, see setAcceptDrops().  \endlist*//*!    Constructs a widget which is a child of \a parent, with  widget    flags set to \a f.    If \a parent is 0, the new widget becomes a window. If    \a parent is another widget, this widget becomes a child window    inside \a parent. The new widget is deleted when its \a parent is    deleted.    The widget flags argument, \a f, is normally 0, but it can be set    to customize the frame of a window (i.e. \a    parent must be 0). To customize the frame, use a value composed    from the bitwise OR of any of the \l{Qt::WindowFlags}{window flags}.    If you add a child widget to an already visible widget you must    explicitly show the child to make it visible.    Note that the X11 version of Qt may not be able to deliver all    combinations of style flags on all systems. This is because on    X11, Qt can only ask the window manager, and the window manager    can override the application's settings. On Windows, Qt can set    whatever flags you want.    \sa windowFlags*/QWidget::QWidget(QWidget *parent, Qt::WindowFlags f)    : QObject(*new QWidgetPrivate, 0), QPaintDevice(){    d_func()->init(parent, f);}#ifdef QT3_SUPPORT/*!    \overload    \obsolete */QWidget::QWidget(QWidget *parent, const char *name, Qt::WindowFlags f)    : QObject(*new QWidgetPrivate, 0), QPaintDevice(){    d_func()->init(parent , f);    setObjectName(QString::fromAscii(name));}#endif/*! \internal*/QWidget::QWidget(QWidgetPrivate &dd, QWidget* parent, Qt::WindowFlags f)    : QObject(dd, 0), QPaintDevice(){    d_func()->init(parent, f);}/*!    \internal*/int QWidget::devType() const{    return QInternal::Widget;}//### w is a "this" ptr, passed as a param because QWorkspace needs special logicvoid QWidgetPrivate::adjustFlags(Qt::WindowFlags &flags, QWidget *w){    bool customize =  (flags & (Qt::CustomizeWindowHint            | Qt::FramelessWindowHint            | Qt::WindowTitleHint            | Qt::WindowSystemMenuHint            | Qt::WindowMinimizeButtonHint            | Qt::WindowMaximizeButtonHint            | Qt::WindowContextHelpButtonHint));    uint type = (flags & Qt::WindowType_Mask);    if ((type == Qt::Widget || type == Qt::SubWindow) && w && !w->parent()) {        type = Qt::Window;        flags |= Qt::Window;    }    if (customize)        ;    else if (type == Qt::Dialog || type == Qt::Sheet)        flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowContextHelpButtonHint;    else if (type == Qt::Tool)        flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint;    else        flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint;}void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f){    Q_Q(QWidget);    if (qApp->type() == QApplication::Tty)        qFatal("QWidget: Cannot create a QWidget when no GUI is being used");    Q_ASSERT(uncreatedWidgets);    uncreatedWidgets->insert(q);    QWidget *desktopWidget = 0;    if (parentWidget && parentWidget->windowType() == Qt::Desktop) {        desktopWidget = parentWidget;        parentWidget = 0;    }    q->data = &data;#ifndef QT_NO_THREAD    if (!q->parent()) {        Q_ASSERT_X(q->thread() == qApp->thread(), "QWidget",                   "Widgets must be created in the GUI thread.");    }#endif#if defined(Q_WS_X11)    if (desktopWidget) {        // make sure the widget is created on the same screen as the        // programmer specified desktop widget        xinfo = desktopWidget->d_func()->xinfo;    }#else    Q_UNUSED(desktopWidget);#endif    data.fstrut_dirty = true;    data.winid = 0;    data.widget_attributes = 0;    data.window_flags = f;    data.window_state = 0;    data.focus_policy = 0;    data.context_menu_policy = Qt::DefaultContextMenu;    data.window_modality = Qt::NonModal;    data.sizehint_forced = 0;    data.is_closing = 0;    data.in_show = 0;    data.in_set_window_state = 0;    data.in_destructor = false;    q->setAttribute(Qt::WA_QuitOnClose); // might be cleared in create()    q->setAttribute(Qt::WA_WState_Hidden);    //give potential windows a bigger "pre-initial" size; create_sys() will give them a new size later    data.crect = parentWidget ? QRect(0,0,100,30) : QRect(0,0,640,480);    focus_next = focus_prev = q;    if ((f & Qt::WindowType_Mask) == Qt::Desktop)        q->create();    else if (parentWidget)        q->setParent(parentWidget, data.window_flags);    else {        adjustFlags(data.window_flags, q);        resolveLayoutDirection();    }#if defined(Q_WS_X11)    data.fnt.x11SetScreen(xinfo.screen());#endif // Q_WS_X11    q->setAttribute(Qt::WA_PendingMoveEvent);    q->setAttribute(Qt::WA_PendingResizeEvent);    if (++QWidgetPrivate::instanceCounter > QWidgetPrivate::maxInstances)        QWidgetPrivate::maxInstances = QWidgetPrivate::instanceCounter;    if (QApplicationPrivate::app_compile_version < 0x040200        || QApplicationPrivate::testAttribute(Qt::AA_ImmediateWidgetCreation))        q->create();    QEvent e(QEvent::Create);    QApplication::sendEvent(q, &e);    QApplication::postEvent(q, new QEvent(QEvent::PolishRequest));    extraPaintEngine = 0;}void QWidgetPrivate::createRecursively(){    Q_Q(QWidget);    q->create(0, true, true);    for (int i = 0; i < children.size(); ++i) {        QWidget *child = qobject_cast<QWidget *>(children.at(i));        if (child && !child->isHidden() && !child->isWindow() && !child->testAttribute(Qt::WA_WState_Created))            child->d_func()->createRecursively();    }}/*!    Creates a new widget window if \a window is 0, otherwise sets the    widget's window to \a window.    Initializes the window (sets the geometry etc.) if \a    initializeWindow is true. If \a initializeWindow is false, no    initialization is performed. This parameter only makes sense if \a    window is a valid window.    Destroys the old window if \a destroyOldWindow is true. If \a    destroyOldWindow is false, you are responsible for destroying the    window yourself (using platform native code).    The QWidget constructor calls create(0,true,true) to create a    window for this widget.*/void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow){    Q_D(QWidget);    if (testAttribute(Qt::WA_WState_Created) && window == 0)        return;    if (d->data.in_destructor)        return;    Qt::WindowType type = windowType();    Qt::WindowFlags &flags = data->window_flags;    if ((type == Qt::Widget || type == Qt::SubWindow) && !parentWidget()) {        type = Qt::Window;        flags |= Qt::Window;    }    if (parentWidget() && (type & Qt::Window) && !parentWidget()->testAttribute(Qt::WA_WState_Created))        parentWidget()->createWinId();#ifdef QT3_SUPPORT    if (flags & Qt::WStaticContents)        setAttribute(Qt::WA_StaticContents);    if (flags & Qt::WDestructiveClose)        setAttribute(Qt::WA_DeleteOnClose);    if (flags & Qt::WShowModal)        setWindowModality(Qt::ApplicationModal);    if (flags & Qt::WMouseNoMask)        setAttribute(Qt::WA_MouseNoMask);    if (flags & Qt::WGroupLeader)        setAttribute(Qt::WA_GroupLeader);    if (flags & Qt::WNoMousePropagation)        setAttribute(Qt::WA_NoMousePropagation);#endif    if ( type != Qt::Widget && type != Qt::Window && type != Qt::Dialog)        setAttribute(Qt::WA_QuitOnClose, false);    setAttribute(Qt::WA_WState_Created);                        // set created flag    d->create_sys(window, initializeWindow, destroyOldWindow);    // a real toplevel window needs a backing store#ifndef Q_WS_MAC    if (isWindow()) {        delete d->topData()->backingStore;        // QWidgetBackingStore will check this variable, hence it must be 0        d->topData()->backingStore = 0;        d->topData()->backingStore = new QWidgetBackingStore(this);    }#endif    d->setModal_sys();    if (!isWindow() && parentWidget() && parentWidget()->testAttribute(Qt::WA_DropSiteRegistered))        setAttribute(Qt::WA_DropSiteRegistered, true);#ifdef QT_EVAL    extern void qt_eval_init_widget(QWidget *w);    qt_eval_init_widget(this);#endif    // need to force the resting of the icon after changing parents    if (testAttribute(Qt::WA_SetWindowIcon))        d->setWindowIcon_sys(true);    if (isWindow() && !d->topData()->iconText.isEmpty())        d->setWindowIconText_helper(d->topData()->iconText);    if (windowType() != Qt::Desktop) {        d->updateSystemBackground();        if (isWindow() && !testAttribute(Qt::WA_SetWindowIcon))            d->setWindowIcon_sys();    }}/*!    Destroys the widget.    All this widget's children are deleted first. The application    exits if this widget is the main widget.*/QWidget::~QWidget(){    Q_D(QWidget);    d->data.in_destructor = true;#if defined (QT_CHECK_STATE)    if (paintingActive())        qWarning("QWidget: %s (%s) deleted while being painted", className(), name());#endif    // force acceptDrops false before winId is destroyed.    d->registerDropSite(false);#ifndef QT_NO_ACTION    // remove all actions from this widget    for (int i = 0; i < d->actions.size(); ++i) {        QActionPrivate *apriv = d->actions.at(i)->d_func();        apriv->widgets.removeAll(this);    }    d->actions.clear();#endif#ifndef QT_NO_SHORTCUT    // Remove all shortcuts grabbed by this    // widget, unless application is closing    if (!QApplicationPrivate::is_app_closing && testAttribute(Qt::WA_GrabbedShortcut))        qApp->d_func()->shortcutMap.removeShortcut(0, this, QKeySequence());#endif    // delete layout while we still are a valid widget    delete d->layout;    // Remove myself from focus list    Q_ASSERT(d->focus_next->d_func()->focus_prev == this);    Q_ASSERT(d->focus_prev->d_func()->focus_next == this);    if (d->focus_next != this) {        d->focus_next->d_func()->focus_prev = d->focus_prev;        d->focus_prev->d_func()->focus_next = d->focus_next;        d->focus_next = d->focus_prev = 0;    }#ifdef QT3_SUPPORT    if (QApplicationPrivate::main_widget == this) {        // reset main widget        QApplicationPrivate::main_widget = 0;        qApp->quit();    }#endif    clearFocus();#ifdef Q_WIDGET_CACHE_OPAQUEREGIONS     d->setDirtyOpaqueRegion();#endif    if (isWindow() && isVisible() && internalWinId())        hide();    // set all QPointers for this object to zero    QObjectPrivate::clearGuards(this);    if (!d->children.isEmpty())        d->deleteChildren();    QApplication::removePostedEvents(this);    destroy();                                        // platform-dependent cleanup    --QWidgetPrivate::instanceCounter;    if (QWidgetPrivate::uncreatedWidgets) // might have been deleted by ~QApplication        QWidgetPrivate::uncreatedWidgets->remove(this);    QEvent e(QEvent::Destroy);    QCoreApplication::sendEvent(this, &e);}int QWidgetPrivate::instanceCounter = 0;  // Current number of widget instancesint QWidgetPrivate::maxInstances = 0;     // Maximum number of widget instancesvoid QWidgetPrivate::setWinId(WId id)                // set widget identifier{    Q_Q(QWidget);    if (mapper && data.winid) {        mapper->remove(data.winid);        uncreatedWidgets->insert(q);    }    data.winid = id;#if defined(Q_WS_X11)    hd = id; // X11: hd == ident#endif    if (mapper && id) {        mapper->insert(data.winid, q);        uncreatedWidgets->remove(q);    }}void QWidgetPrivate::createTLExtra(){    if (!extra)        createExtra();    if (!extra->topextra) {        QTLWExtra* x = extra->topextra = new QTLWExtra;        x->windowSurface = 0;        x->opacity = 255;        x->posFromMove = false;        x->icon = 0;        x->iconPixmap = 0;        x->frameStrut.setCoords(0, 0, 0, 0);        x->incw = x->inch = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -