繁体   English   中英

Qt QGraphicsProxyWidget 与 QGraphicsScene 的交互

[英]Qt QGraphicsProxyWidget interaction with QGraphicsScene

我正在尝试使用QTreeView的左侧和右侧的QGraphicsView制作QSplitter 这非常简单,我有这个工作。

现在,我的目标是嵌入部件在现场QGraphicsView ,使用QGraphicsProxyWidget创建项目QGraphicsScene我分配给我QGraphicsView 这也非常简单和有效。 有一个关于我希望这些小部件的外观和感觉的小警告。 经过一些研究,根据我自己阅读和测试的内容,这似乎是不可能的。 我将发布我目前所拥有的相关代码,以进一步解释这种情况。

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){
    ui->setupUi(this);

    QPointer<QSplitter> splitter = new QSplitter;

    QPointer<QTreeView> tree = new QTreeView;
    splitter->addWidget(tree);

    QPointer<QVBoxLayout> layout = new QVBoxLayout;
    layout->addWidget(splitter);

    QPointer<QWidget> blueWidget = new QWidget;
    QPointer<QWidget> redWidget = new QWidget;
    blueWidget->setGeometry(250, 500, 250, 250);
    redWidget->setGeometry(500, 500, 250, 250);

    //This has no effect...
    blueWidget->setWindowFlags(Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint);
    redWidget->setWindowFlags( Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint);

    blueWidget->setWindowTitle("Blue Widget");
    redWidget->setWindowTitle("Red Widget");

    blueWidget->setStyleSheet(QString("background-color: rgb(0,0,255)"));
    redWidget->setStyleSheet(QString("background-color: rgb(255,0,0)"));

    QPointer<QGraphicsProxyWidget> proxy1 = new QGraphicsProxyWidget(nullptr, redWidget->windowFlags());
    proxy1->setWidget(redWidget);
    proxy1->setWindowFlags(redWidget->windowFlags());

    QPointer<QGraphicsProxyWidget> proxy2 = new QGraphicsProxyWidget;
    proxy2->setWidget(blueWidget);
    proxy2->setWindowFlags(blueWidget->windowFlags());

    QPointer<QGraphicsScene> scene = new QGraphicsScene;
    scene->addItem(proxy1);
    scene->addItem(proxy2);
    scene->setSceneRect(0,0,1920,1080);

    QPointer<QGraphicsView> view = new QGraphicsView;
    view->setStyleSheet(QString("background-color: rgb(245,245,220)"));
    view->setScene(scene);
    view->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
    view->setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );

    splitter->addWidget(view);
    splitter->setStretchFactor( 0, 1 );
    splitter->setStretchFactor( 1, 3 );
    this->centralWidget()->setLayout(layout);
}

因此,鉴于此代码,我试图为QGraphicsItems中的QGraphicsScene一些Qt::WindowFlags 但是,看起来我要么没有栏(如果我没有设置标志),要么只有一个栏和一个简单的关闭按钮,其样式与程序的其余部分不同(我认为取决于操作系统样式)。 生成的这个标题栏没有弹出右键单击上下文菜单,就像您对常规QWidget所期望的那样。 我只是想知道是否有可能绕过这个似乎由操作系统强加的限制。 没有多少Qt::WindowFlags具有我一直在寻找的任何组合所需的效果。 我希望Qt::Widget就是我所需要的,但它不起作用,也没有明确添加Qt::WindowMinMaxButtonsHint

我在想,也许我可以创建自定义TitleBarWidget / TitleBarItem这需要家长QGraphicsItemQWidget是在QGraphicsScene ,并将其应用到其父的宽度偏移相匹配。 然后我可以实现这个TitleBarWidget的点击和拖动事件来移动它的父级。 这样做可以让我添加自己的自定义标题定位、字体甚至颜色。 此外,我可以创建自己的自定义样式按钮并连接它们的点击信号以执行常规QWidget将执行的相应正确操作。

如果这看起来很复杂,那么这样做的目的是保持QGraphicsItems永远不会离开QSplitter's QGraphicsView QGraphicsScene's边界矩形区域的属性。 我也有一个解决最小化和最大化的想法,因为如果最小化它,将没有本地操作系统任务栏应用程序可供选择。

现在,如果没有工作,我不得不用顶级来创建自己的场景管理QWidgets并连接每一个QWidget's resize事件,以发出QSplitter's拖动事件......,我真的不想要做的.. .

拜托,如果我在第一次尝试的实现中错过了一些基本的东西,可以让它以最少的麻烦工作,如果有人能指出我正确的方向,我们将不胜感激。 如果我对TitleBarWidgetTitleBarItem第二个想法可能是我最好的选择,并且最少的子类化和重组,那么我会继续这样做。 我担心这也行不通,但我很乐观,如果它没有遇到与第一个实现相同的问题,我可以让它工作。

经过多天的反复试验,我已经完成了之前引用的链接中先前用户代码的修改版本。 这个Titlebar类可以附加到任何更大的QWidget ,作为整个窗口的区域。 您基本上需要使用QVBoxLayout创建一个QWidget 然后,创建另一个QWidget来保存窗口的实际内容,并将整个外部父QWidget设置为该Titlebar's父级。 这将允许您自由设置Titlebar样式并添加您希望的任何按钮、图标、样式,而与您的操作系统无关。

#ifndef TITLEBAR_H
#define TITLEBAR_H

#include "ViewerItem.h"
#include <QWidget>
#include <QHBoxLayout>
#include <QPushButton>
#include <QPointer>
#include <QStyle>
#include <QLabel>
#include <QPainter>
#include <QPen>
#include <QMouseEvent>
#include <QEvent>
#include <QApplication>
#include <QRubberBand>
#include <QEvent>
#include <QPoint>
#include <QResizeEvent>
#include <QObject>
#include <QDebug>
#include <QGraphicsProxyWidget>
#include <QGraphicsView>

class ViewerItem;

class TitleBar : public QWidget{
    Q_OBJECT
public:
    TitleBar(QString title = "default", QWidget *parent = nullptr);
    void setWindowTitle(const QString& title);

    enum Edge{
        None = 0x0,
        Left = 0x1,
        Top = 0x2,
        Right = 0x4,
        Bottom = 0x8,
        TopLeft = 0x10,
        TopRight = 0x20,
        BottomLeft = 0x40,
        BottomRight = 0x80,
    };
    Q_ENUM(Edge);
    Q_DECLARE_FLAGS(Edges, Edge);

    void setBorderWidth(int);
    int borderWidth() const;

    ViewerItem *_parent = nullptr;
    QRubberBand *_rubberband = nullptr;
    bool _cursorchanged;
    bool _leftButtonPressed;
    Edges* _mousePress;
    Edges* _mouseMove;
    int _borderWidth;
    bool _dragStart = false;
    Qt::CursorShape _prevCursorShape = Qt::ArrowCursor;

protected slots:
    void paintEvent(QPaintEvent* event);
protected:
    bool eventFilter(QObject *o, QEvent *e) override;
    void mouseHover(QHoverEvent*);
    void mouseLeave(QHoverEvent *);
    void mousePress(QMouseEvent*);
    void mouseRelease(QMouseEvent*);
    void mouseMove(QMouseEvent*);
    void updateCursorShape(const QPoint &);
    void calculateCursorPosition(const QPoint &, const QRect &, Edges *);

private:
    QPointer<QStyle> style;

    QIcon closeIcon;
    QIcon maxIcon;
    QIcon minIcon;

    QPointer<QLabel> titleLabel;
    QPointer<QPushButton> minimizeButton;
    QPointer<QPushButton> maximizeButton;
    QPointer<QPushButton> closeButton;

    QPointer<QVBoxLayout> mainVLayout;
    QPointer<QHBoxLayout> mainHLayout;
    QPointer<QHBoxLayout> leftHLayout;
    QPointer<QHBoxLayout> rightHLayout;

    QPoint currentPos;

    QPointer<QGraphicsView> view;

};

Q_DECLARE_OPERATORS_FOR_FLAGS(TitleBar::Edges);

#endif // TITLEBAR_H

#include "Titlebar.h"

TitleBar::TitleBar(QString title, QWidget *parent) :
    QWidget(parent),
    _parent(qobject_cast<ViewerItem*>(parent)),
    _cursorchanged(false),
    _leftButtonPressed(false),
    _borderWidth(5){

        titleLabel = new QLabel;
        minimizeButton = new QPushButton;
        maximizeButton = new QPushButton;
        closeButton = new QPushButton;

        mainVLayout = new QVBoxLayout;
        mainHLayout = new QHBoxLayout;
        leftHLayout = new QHBoxLayout;
        rightHLayout = new QHBoxLayout;

        leftHLayout->addWidget(titleLabel);

        rightHLayout->addWidget(minimizeButton);
        rightHLayout->addWidget(maximizeButton);
        rightHLayout->addWidget(closeButton);

        mainHLayout->addLayout(leftHLayout);
        mainHLayout->addLayout(rightHLayout);

        mainVLayout->setAlignment(Qt::AlignTop);
        leftHLayout->setAlignment(Qt::AlignLeft);
        rightHLayout->setAlignment(Qt::AlignRight);
        mainVLayout->setContentsMargins(5,2.5,5,0);


        mainVLayout->addLayout(mainHLayout);
        setLayout(mainVLayout);

        setWindowTitle(title);

        style = qApp->style();
        closeIcon = style->standardIcon(QStyle::SP_TitleBarCloseButton);
        maxIcon = style->standardIcon(QStyle::SP_TitleBarMaxButton);
        minIcon = style->standardIcon(QStyle::SP_TitleBarMinButton);

        minimizeButton->setIcon(minIcon);
        maximizeButton->setIcon(maxIcon);
        closeButton->setIcon(closeIcon);

        minimizeButton->setMinimumWidth(30);
        maximizeButton->setMinimumWidth(30);
        closeButton->setMinimumWidth(30);

        titleLabel->setFixedHeight(20);

        minimizeButton->setFixedHeight(20);
        maximizeButton->setFixedHeight(20);
        closeButton->setFixedHeight(20);

        this->setFixedHeight(25);
        this->setMinimumWidth(90);

        //_parent->setMouseTracking(true);
        _parent->setWindowFlags(Qt::FramelessWindowHint);
        _parent->setAttribute(Qt::WA_Hover);
        _parent->installEventFilter(this);

        _rubberband = new QRubberBand(QRubberBand::Rectangle);

        _mousePress = new Edges(Edge::None);
        _mouseMove = new Edges(Edge::None);
}

void TitleBar::paintEvent(QPaintEvent *event){
    QPainter p(this);
    p.setRenderHint(QPainter::Antialiasing);
    QPainterPath path;
    path.addRect(QRectF(0, 0, width(), height()));
    QPen pen(Qt::black, 1);
    p.setPen(pen);
    p.fillPath(path, Qt::white);
    p.drawPath(path);

    QWidget::paintEvent(event);
}



void TitleBar::setWindowTitle(const QString& title){
    this->titleLabel->setText(title);
    QWidget::setWindowTitle(title);
}

bool TitleBar::eventFilter(QObject *o, QEvent*e) {
    if (e->type() == QEvent::MouseMove ||
        e->type() == QEvent::HoverMove ||
        e->type() == QEvent::Leave ||
        e->type() == QEvent::MouseButtonPress ||
        e->type() == QEvent::MouseButtonRelease) {


        switch (e->type()) {
            case QEvent::MouseMove:
                mouseMove(static_cast<QMouseEvent*>(e));
                return true;
                break;
            case QEvent::HoverMove:
                mouseHover(static_cast<QHoverEvent*>(e));
                return true;
                break;
            case QEvent::Leave: //We're actually leaving the widget after we go out of the geometry + borderWidth
                mouseLeave(static_cast<QHoverEvent*>(e));
                return true;
                break;
            case QEvent::MouseButtonPress:
                mousePress(static_cast<QMouseEvent*>(e));
                return true;
                break;
            case QEvent::MouseButtonRelease:
                mouseRelease(static_cast<QMouseEvent*>(e));
                return true;
                break;
            default:
                //e->accept();
                return true;
                break;
        }
    } else {
        return _parent->eventFilter(o, e);
    }

}

void TitleBar::mouseHover(QHoverEvent *e) {
    //if this parent object is in a container we need to mapToParent, not mapToGlobal like the original implementer's code
    updateCursorShape(_parent->mapToParent(e->pos()));

    //We need to make the bar transparent because it messes with the leave event of the widget "behind" it for the top, top left, and top right cursors
    //Only re-enable it when we want to for example, double click maximize or click the buttons
    //This will be determined if we're within the the bar's bounding rect minus the border value, in other words the cursor should be defaulted
    //This will prevent accidental drag events also
    if(this->geometry().marginsRemoved(QMargins(borderWidth(),borderWidth(),borderWidth(), 0)).contains(e->pos())){
        setAttribute(Qt::WA_TransparentForMouseEvents, false);
    }else{
        setAttribute(Qt::WA_TransparentForMouseEvents, true);
    }
    e->accept();
}

void TitleBar::mouseLeave(QHoverEvent *e) {
    if (!_leftButtonPressed) {
        *_mousePress = None;
        *_mouseMove = None;
        QApplication::restoreOverrideCursor();
        _cursorchanged = false;
        _prevCursorShape = Qt::ArrowCursor;
    }
    QWidget::leaveEvent(e);
}

void TitleBar::mousePress(QMouseEvent *e) {
    if(e->button() & Qt::LeftButton){
        _leftButtonPressed = true;
        currentPos = e->pos();
        calculateCursorPosition(e->pos(), _parent->geometry().marginsRemoved(QMargins(_borderWidth, _borderWidth, _borderWidth, _borderWidth)), _mousePress);
        if (!_mouseMove->testFlag(Edge::None)) {
            _rubberband->setGeometry(_parent->geometry());
        }

        //This area is ONLY on the title bar itself and determines repositioning of the parent
        //We're actually selecting the parent, not the bar, but it looks and feels like we are using the bar
        if(this->geometry().marginsRemoved(QMargins(borderWidth(),borderWidth() + 1,borderWidth(),0)).contains(e->pos())){
            _dragStart = true;
            _cursorchanged = false;
        }
    }
    e->accept();
}

void TitleBar::mouseRelease(QMouseEvent *e) {
    if (e->button() & Qt::LeftButton) {
        _leftButtonPressed = false;
        _dragStart = false;
    }
    e->accept();
}

void TitleBar::mouseMove(QMouseEvent *e) {
    if (_leftButtonPressed) {
        //For dragging the parent by its titlebar
        if (_dragStart) {
            QPoint diff = e->pos() - currentPos;
            _parent->move(_parent->pos() + diff);
            return;
        }

        //For determining how to resize if we have an edge
        if (!_mouseMove->testFlag(Edge::None)) {
            int left = _rubberband->geometry().left();
            int top = _rubberband->geometry().top();
            int right = _rubberband->geometry().right();
            int bottom = _rubberband->geometry().bottom();

            switch (*_mouseMove) {

                case Edge::Top:
                    top = e->pos().y();                 
                    if(_parent->height() - top <= _parent->minimumHeight()) top = 0;
                    _parent->resize(QSize(_parent->width(), _parent->height() - top));
                    _rubberband->resize(QSize(_parent->width(), _parent->height() - top));                    
                    _parent->move(QPoint(_parent->x(), _parent->y() + top));
                    _rubberband->move(QPoint(_parent->x(), _parent->y() + top));
                    break;

                case Edge::Bottom: //Good
                    bottom = e->pos().y();
                    if(bottom > _parent->height()){ //growing down
                        _parent->resize(QSize(_parent->width(), _parent->height() + (bottom - _parent->height())));
                        _rubberband->resize(QSize(_parent->width(), _parent->height() + (bottom - _parent->height())));
                    }else{ //shrinking up
                        _parent->resize(QSize(_parent->width(), _parent->height() - (_parent->height() - bottom)));
                        _rubberband->resize(QSize(_parent->width(), _parent->height() - (_parent->height() - bottom)));
                    }
                    break;

                case Edge::Left: //Good
                    left = e->pos().x();
                    if(left <= 0){ //Dragging left
                        if(_parent->width() - left <= _parent->minimumWidth()) left = 0;
                        _parent->resize(QSize(_parent->width() - left, _parent->height()));
                        _rubberband->resize(QSize(_parent->width() - left, _parent->height()));
                        _parent->move(QPoint(_parent->x() + left, _parent->y()));
                        _rubberband->move(QPoint(_parent->x() + left, _parent->y()));
                    }else{ //dragging right
                        if(_parent->width() - left <= _parent->minimumWidth()) left = 0;
                        _parent->resize(QSize(_parent->width() - left, _parent->height()));
                        _rubberband->resize(QSize(_parent->width() - left, _parent->height()));
                        _parent->move(QPoint(_parent->x() + left, _parent->y()));
                        _rubberband->move(QPoint(_parent->x() + left, _parent->y()));
                    }
                    break;

                case Edge::Right:
                    right = e->pos().x();
                    if(right >= 0){ //Dragging right
                        _parent->resize(QSize(right, _parent->height()));
                        _rubberband->resize(QSize(right, _parent->height()));
                        if(_parent->width() - right <= _parent->minimumWidth()) break;
                        _parent->move(QPoint(_parent->x() + (_parent->width() - right), _parent->y()));
                        _rubberband->move(QPoint(_parent->x() + (_parent->width() - right), _parent->y()));
                    }
                    break;

                case Edge::TopLeft:
                    top = e->pos().y();
                    left = e->pos().x();
                    if(_parent->height() - top <= _parent->minimumHeight()) top = 0;
                    if(_parent->width() - left <= _parent->minimumWidth()) left = 0;
                    _parent->resize(QSize(_parent->width() - left, _parent->height() - top));
                    _rubberband->resize(QSize(_parent->width() - left, _parent->height() - top));
                    _parent->move(QPoint(_parent->x() + left, _parent->y() + top));
                    _rubberband->move(QPoint(_parent->x() + left, _parent->y() + top));
                    break;

                case Edge::TopRight:
                    right = e->pos().x();
                    top = e->pos().y();
                    if(_parent->height() - top <= _parent->minimumHeight()) top = 0;
                    _parent->resize(QSize(_parent->width(), _parent->height() - top));
                    _rubberband->resize(QSize(_parent->width(), _parent->height() - top));
                    _parent->move(QPoint(_parent->x(), _parent->y() + top));
                    _rubberband->move(QPoint(_parent->x(), _parent->y() + top));
                    if(right >= 0){ //Dragging right
                        _parent->resize(QSize(right, _parent->height()));
                        _rubberband->resize(QSize(right, _parent->height()));
                        if(_parent->width() - right <= _parent->minimumWidth()) break;
                        _parent->move(QPoint(_parent->x() + (_parent->width() - right), _parent->y()));
                        _rubberband->move(QPoint(_parent->x() + (_parent->width() - right), _parent->y()));
                    }
                    break;
                case Edge::BottomLeft:
                    bottom = e->pos().y();
                    left = e->pos().x();
                    if(bottom > _parent->height()){ //growing down
                        _parent->resize(QSize(_parent->width(), _parent->height() + (bottom - _parent->height())));
                        _rubberband->resize(QSize(_parent->width(), _parent->height() + (bottom - _parent->height())));
                    }else{ //shrinking up
                        _parent->resize(QSize(_parent->width(), _parent->height() - (_parent->height() - bottom)));
                        _rubberband->resize(QSize(_parent->width(), _parent->height() - (_parent->height() - bottom)));
                    }
                    if(left <= 0){ //Dragging left
                        if(_parent->width() - left <= _parent->minimumWidth()) left = 0;
                        _parent->resize(QSize(_parent->width() - left, _parent->height()));
                        _rubberband->resize(QSize(_parent->width() - left, _parent->height()));
                        _parent->move(QPoint(_parent->x() + left, _parent->y()));
                        _rubberband->move(QPoint(_parent->x() + left, _parent->y()));
                    }else{ //dragging right
                        if(_parent->width() - left <= _parent->minimumWidth()) left = 0;
                        _parent->resize(QSize(_parent->width() - left, _parent->height()));
                        _rubberband->resize(QSize(_parent->width() - left, _parent->height()));
                        _parent->move(QPoint(_parent->x() + left, _parent->y()));
                        _rubberband->move(QPoint(_parent->x() + left, _parent->y()));
                    }
                    break;
                case Edge::BottomRight:
                    bottom = e->pos().y();
                    right = e->pos().x();
                    if(bottom > _parent->height()){ //growing down
                        _parent->resize(QSize(_parent->width(), _parent->height() + (bottom - _parent->height())));
                        _rubberband->resize(QSize(_parent->width(), _parent->height() + (bottom - _parent->height())));
                    }else{ //shrinking up
                        _parent->resize(QSize(_parent->width(), _parent->height() - (_parent->height() - bottom)));
                        _rubberband->resize(QSize(_parent->width(), _parent->height() - (_parent->height() - bottom)));
                    }
                    if(right >= 0){ //Dragging right
                        _parent->resize(QSize(right, _parent->height()));
                        _rubberband->resize(QSize(right, _parent->height()));
                        if(_parent->width() - right <= _parent->minimumWidth()) break;
                        _parent->move(QPoint(_parent->x() + (_parent->width() - right), _parent->y()));
                        _rubberband->move(QPoint(_parent->x() + (_parent->width() - right), _parent->y()));
                    }
                    break;
                default:
                    break;
            }
        }
    }
    e->accept();
}

void TitleBar::updateCursorShape(const QPoint &pos) {
    if (_parent->isFullScreen() || _parent->isMaximized()) {
        if (_cursorchanged) {
            QApplication::restoreOverrideCursor();
        }
        return;
    }
    if (!_leftButtonPressed) {
        calculateCursorPosition(pos, _parent->geometry(), _mouseMove);
        _cursorchanged = true;
        if (_mouseMove->testFlag(Edge::Top) || _mouseMove->testFlag(Edge::Bottom)) {
            if(_prevCursorShape != Qt::SizeVerCursor){
                QApplication::setOverrideCursor(Qt::SizeVerCursor);
            }
            _prevCursorShape = Qt::SizeVerCursor;
        } else if (_mouseMove->testFlag(Edge::Left) || _mouseMove->testFlag(Edge::Right)) {
            if(_prevCursorShape != Qt::SizeHorCursor){
                QApplication::setOverrideCursor(Qt::SizeHorCursor);
            }
            _prevCursorShape = Qt::SizeHorCursor;
        } else if (_mouseMove->testFlag(Edge::TopLeft) || _mouseMove->testFlag(Edge::BottomRight)) {
            if(_prevCursorShape != Qt::SizeFDiagCursor){
                QApplication::setOverrideCursor(Qt::SizeFDiagCursor);
            }
            _prevCursorShape = Qt::SizeFDiagCursor;
        } else if (_mouseMove->testFlag(Edge::TopRight) || _mouseMove->testFlag(Edge::BottomLeft)) {
            if(_prevCursorShape != Qt::SizeBDiagCursor){
                QApplication::setOverrideCursor(Qt::SizeBDiagCursor);
            }
            _prevCursorShape = Qt::SizeBDiagCursor;
        } else if (_cursorchanged && _mouseMove->testFlag(Edge::None)) {
            QApplication::restoreOverrideCursor();
            _cursorchanged = false;
            _prevCursorShape = Qt::ArrowCursor;
        }
    }
}

void TitleBar::calculateCursorPosition(const QPoint &pos, const QRect &framerect, Edges* _edge) {

    bool onLeft = pos.x() >= framerect.x() + _borderWidth && pos.x() <= framerect.x() + (_borderWidth * 2) &&
        pos.y() <= framerect.y() + framerect.height() - (_borderWidth * 4) && pos.y() >= framerect.y() + (_borderWidth * 4);

    bool onRight = pos.x() >= framerect.x() + framerect.width() - (_borderWidth * 2) && pos.x() <= framerect.x() + framerect.width() - (_borderWidth) &&
        pos.y() >= framerect.y() + (_borderWidth * 4) && pos.y() <= framerect.y() + framerect.height() - (_borderWidth * 4);

    bool onBottom = pos.x() >= framerect.x() + (_borderWidth * 4) && pos.x() <= framerect.x() + framerect.width() - (_borderWidth * 4) &&
        pos.y() >= framerect.y() + framerect.height() - (_borderWidth * 2) && pos.y() <= framerect.y() + framerect.height() - _borderWidth;

    bool onTop = pos.x() >= framerect.x() + (_borderWidth * 4) && pos.x() <= framerect.x() + framerect.width() - (_borderWidth  * 4) &&
        pos.y() >= framerect.y() + _borderWidth && pos.y() <= framerect.y() + (_borderWidth * 2);

    bool onBottomLeft = pos.x() <= framerect.x() + (_borderWidth * 3) && pos.x() >= framerect.x() + _borderWidth &&
        pos.y() <= framerect.y() + framerect.height() -_borderWidth && pos.y() >= framerect.y() + framerect.height() - (_borderWidth * 4);

    bool onBottomRight = pos.x() >= framerect.x() + framerect.width() - (_borderWidth * 4) && pos.x() <= framerect.x() + framerect.width() - _borderWidth &&
        pos.y() >= framerect.y() + framerect.height() - (_borderWidth * 4) && pos.y() <= framerect.y() + framerect.height() - _borderWidth;

    bool onTopRight = pos.x() >= framerect.x() + framerect.width() - (_borderWidth * 4) && pos.x() <= framerect.x() + framerect.width() - _borderWidth &&
        pos.y() >= framerect.y() + _borderWidth && pos.y() <= framerect.y() + (_borderWidth * 4);

    bool onTopLeft = pos.x() >= framerect.x() - _borderWidth && pos.x() <= framerect.x() + (_borderWidth * 4) &&
        pos.y() >= framerect.y() + _borderWidth && pos.y() <= framerect.y() + (_borderWidth * 4);

    if (onLeft) {
        *_edge = Left;
        //qDebug() << "Left";
    } else if (onRight) {
        *_edge = Right;
        //qDebug() << "Right";
    } else if (onBottom) {
        *_edge = Bottom;
        //qDebug() << "bottom";
    } else if (onTop) {
        *_edge = Top;
        //qDebug() << "top";
    } else if (onBottomLeft) {
        *_edge = BottomLeft;
        //qDebug() << "bottom left";
    } else if (onBottomRight) {
        *_edge = BottomRight;
        //qDebug() << "Bottom right";
    } else if (onTopRight) {
        *_edge = TopRight;
        //qDebug() << "Top right";
    } else if (onTopLeft) {
        *_edge = TopLeft;
        //qDebug() << "Top left";
    } else {
        *_edge = None;
        //qDebug() << "None";
    }

}

void TitleBar::setBorderWidth(int borderWidth) {
    _borderWidth = borderWidth;
}

int TitleBar::borderWidth() const {
    return _borderWidth;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM