当前位置:   article > 正文

qt 自定义最大化,最小化,还原,解决还原位置不对等问题_qt 最小化、最大化(还原)显示不全

qt 最小化、最大化(还原)显示不全

//初始化最大化/还原、最小化,关闭的按钮,并关联槽函数
CloseButton= new QPushButton(this);
maxButton= new QPushButton(this);
mixButton= new QPushButton(this);
initRightButton();
connect(CloseButton,&QPushButton::clicked,this,&helloWord::closesWindow);
connect(maxButton,&QPushButton::clicked,this,&helloWord::maxsWindow);
connect(mixButton,&QPushButton::clicked,this,&helloWord::mixsWindow);

helloWord::~helloWord()
{
delete ui;
}
//初始化按钮的位置(右上角)
void helloWord::initRightButton(int x, int y)
{

CloseButton->setGeometry(this->frameGeometry().width()-closeWidght,this->pos().y(),closeWidght,closeHeight);
CloseButton->setStyleSheet(QString("QPushButton{border-image:url(:/new/prefix1/image/close.png);}"
                                   "QPushButton:hover{border-image:url(:/new/prefix1/image/close(hieght).png)}"));

maxButton->setGeometry(this->frameGeometry().width()-closeWidght-maxWidght,this->pos().y(),maxWidght,maxHeight);

mixButton->setGeometry(this->frameGeometry().width()-closeWidght-maxWidght-mixWidght,this->pos().y(),mixWidght,mixHeight);
mixButton->setStyleSheet(QString("QPushButton{border-image:url(:/new/prefix1/image/mix.png);}"));
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

}

void helloWord::closesWindow()
{
this->close();
}
//实现最大化/最小化功能,并解决还原位置不对的问题
void helloWord::maxsWindow()
{

qDebug()<<rect0.x()<<rect0.y();
if(WindowMarker ==0)
{
    //记住原来的位置
    rect0 = geometry();
    Sourcex = rect0.x();
    Sourcey = rect0.y();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

// //获取分辨率
QScreen* screen=QGuiApplication::primaryScreen ();
QRect mm=screen->availableGeometry() ;
int Maxnum =mm.width();
int Mixnum =mm.height();
//设置最大化
setFixedSize(Maxnum,Mixnum);

     move(0,0);
    initRightButton();
    WindowMarker =1;

}else if(WindowMarker == 1)
{
    //设置界面大小
    setFixedSize( Sourcewidght,SourceHeight);
    //初始化按钮位置
     initRightButton();
    qDebug()<<Sourcex<<Sourcey;
    //还原位置
    move(Sourcex,Sourcey);

    WindowMarker =0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

}
//实现最小化功能
void helloWord::mixsWindow()
{
showMinimized();
}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/95014
推荐阅读
相关标签
  

闽ICP备14008679号