qml fade animation

qml fade animation

Turn on property animation, set linear change easing.type
opacityAnimation.running = false//close
opacityAnimation.running = true//open

  PropertyAnimation{
    
    
        id: opacityAnimation
        target: root
        property: "opacity"
        from: 1
        to: 0
        duration: 2000
        easing.type: Easing.InExpo
    }

Show label on top of Dialog modal window

Set the window property setWindowFlags(Qt::Popup)

lose focus tab disappears

override focus event

void ScreenTip::hideTip()
{
    
    
    this->hide();
}

//重写失去焦点的事件循环
bool ScreenTip::eventFilter(QObject *o, QEvent *e)
{
    
    
    if (e->type() == QEvent::ActivationChange)
    {
    
    
        if(QApplication::activeWindow() != this)
        {
    
    
            hideTip();
        }
    }
    return QWidget::eventFilter(o,e);
}

Intercept events in child windows

The event goes to the child window first and then to the parent window
. If an event filter is registered, the event goes to the object with the filter installed first
event->ignore(); //Ignore the exit signal and the program continues to run
event->accept() ; //Accept the exit signal, the program exits

Realize movable window, no qt window frame

.h

private:
    bool m_bDrag;                        // 是否正在拖动
    QPoint mouseStartPoint;        // 拖动开始前的鼠标位置
    QPoint windowTopLeftPoint;        // 窗体的原始位置
public:
     void mousePressEvent(QMouseEvent* event);
     void mouseMoveEvent(QMouseEvent* event);
     void mouseReleaseEvent(QMouseEvent* event);

.cpp

ClassName::ClassName(QWidget *parent) : QDialog(parent)
{
    
    
    setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
    setAttribute(Qt::WA_NoSystemBackground,  true);
    setAttribute(Qt::WA_TranslucentBackground);
    ... ...
}

void ClassName::mousePressEvent(QMouseEvent *event)
{
    
    
    if(event->button() == Qt::LeftButton)
        {
    
    
            m_bDrag = true;
            //获得鼠标的初始位置
            mouseStartPoint = event->globalPos();
            //mouseStartPoint = event->pos();
            //获得窗口的初始位置
            windowTopLeftPoint = this->frameGeometry().topLeft();
        }
}

void ClassName::mouseMoveEvent(QMouseEvent *event)
{
    
    
    if(m_bDrag)
        {
    
    
            //获得鼠标移动的距离
            QPoint distance = event->globalPos() - mouseStartPoint;
            //QPoint distance = event->pos() - mouseStartPoint;
            //改变窗口的位置
            this->move(windowTopLeftPoint + distance);
        }
}

void ClassName::mouseReleaseEvent(QMouseEvent *event)
{
    
    
    if(event->button() == Qt::LeftButton)
        {
    
    
            m_bDrag = false;
        }
}

Jump link QDesktopServices::openUrl

//本地
localPath.replace("/","\\");
QDesktopServices::openUrl(QUrl::fromLocalFile(localPath));
//网页
QDesktopServices::openUrl(QUrl(https://www.baidu.com/));

device screen size

QScreen  *systemScreen = QGuiApplication::primaryScreen();
QSize  mySize = systemScreen->geometry().size();
//除去任务栏大小systemScreen->availableGeometry().size()

qml implements a draggable rectangular marquee

The idea is to use Mousearea's drag to implement a draggable marquee, place a small rectangle for dragging on each of the four corners and four sides, bind the corners of the large rectangle to the corners of the small rectangle, and use the onPositionChanged slot function of the small rectangle It calculates the position of the large rectangle in real time, and considers various situations by classification, such as the corner of the large rectangle exceeds the boundary or the value of the side of the large rectangle cannot be negative.

Realize qml interface penetration

Add propagateComposedEvents in MouseArea: true//Set to propagate mouse events
and set mouse.accepted = false at the same time//Do not accept mouse events, pass events to the lower layer MouseArea
The description of propagateComposedEvents in QT is whether this property saves the combined mouse events automatically Propagate to other mouse regions that overlap this mouse region but are lower in the visual stack order. By default, this property is false.

  Rectangle {
    
    
        anchors.centerIn: parent
        color: "yellow"
        width: 100; height: 100
        
        MouseArea {
    
    
            anchors.fill: parent
            onClicked: console.log("clicked yellow")
        }
        
        Rectangle {
    
    
            color: "blue"
            width: 50; height: 50
            anchors.centerIn: parent
            
            MouseArea {
    
    
                anchors.fill: parent
                propagateComposedEvents: true
                onClicked: {
    
    
                    console.log("clicked blue")
                    mouse.accepted = false
                }
            }
        }
    }

insert image description here

insert image description here
Reference URL:

https://www.cnblogs.com/SaveDictator/articles/7411894.html

Guess you like

Origin blog.csdn.net/caicai_xiaobai/article/details/117771377