setMinimumSize(0, 0); setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); this->m_frame->setMinimumSize(0, 0); 解决主frame拖动子mainwindow不跟随的问题qt6
parent
1c7d843a04
commit
d34a6c8818
108
Qss.cpp
108
Qss.cpp
|
@ -35,6 +35,18 @@
|
||||||
#define QSSDIALOG_SHADOW_WIDTH 12
|
#define QSSDIALOG_SHADOW_WIDTH 12
|
||||||
#define QSSDIALOG_BODER_WIDTH 0
|
#define QSSDIALOG_BODER_WIDTH 0
|
||||||
|
|
||||||
|
enum {
|
||||||
|
TOPLEFT = 11,
|
||||||
|
TOP = 12,
|
||||||
|
TOPRIGHT = 13,
|
||||||
|
LEFT = 21,
|
||||||
|
CENTER = 22,
|
||||||
|
RIGHT = 23,
|
||||||
|
BUTTOMLEFT = 31,
|
||||||
|
BUTTOM = 32,
|
||||||
|
BUTTOMRIGHT = 33
|
||||||
|
};
|
||||||
|
|
||||||
static void rangeObjectList(QObject*obj,int indent){
|
static void rangeObjectList(QObject*obj,int indent){
|
||||||
QObjectList child = obj->children();
|
QObjectList child = obj->children();
|
||||||
QString tmp("");
|
QString tmp("");
|
||||||
|
@ -107,6 +119,7 @@ QssTtitleBar::QssTtitleBar(QWidget *parent ,
|
||||||
}else{
|
}else{
|
||||||
connect(m_closeBtn, SIGNAL(clicked()), parent, SLOT(close()));
|
connect(m_closeBtn, SIGNAL(clicked()), parent, SLOT(close()));
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(m_minBtn, SIGNAL(clicked()), parent, SLOT(showMinimized()));
|
connect(m_minBtn, SIGNAL(clicked()), parent, SLOT(showMinimized()));
|
||||||
connect(m_maxBtn, SIGNAL(clicked()), this, SLOT(onMaxOrRestore()));
|
connect(m_maxBtn, SIGNAL(clicked()), this, SLOT(onMaxOrRestore()));
|
||||||
connect(m_restoreBtn, SIGNAL(clicked()), this, SLOT(onMaxOrRestore()));
|
connect(m_restoreBtn, SIGNAL(clicked()), this, SLOT(onMaxOrRestore()));
|
||||||
|
@ -120,7 +133,7 @@ QssTtitleBar::QssTtitleBar(QWidget *parent ,
|
||||||
|
|
||||||
QFile file(":/qss/css/QssTitleBar.css");
|
QFile file(":/qss/css/QssTitleBar.css");
|
||||||
if (!file.open(QIODevice::ReadOnly)){
|
if (!file.open(QIODevice::ReadOnly)){
|
||||||
qDebug()<<"error bar";
|
qDebug()<<"error open QssTitleBar";
|
||||||
}
|
}
|
||||||
QTextStream in(&file);
|
QTextStream in(&file);
|
||||||
QString css = in.readAll();
|
QString css = in.readAll();
|
||||||
|
@ -226,8 +239,7 @@ bool QssTtitleBar::eventFilter( QObject * obj, QEvent * ev )
|
||||||
return QWidget::eventFilter(obj, ev);
|
return QWidget::eventFilter(obj, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QssMainWindow::OnMaxOrRestore(bool max)
|
void QssMainWindow::OnMaxOrRestore(bool max) {
|
||||||
{
|
|
||||||
if (max)
|
if (max)
|
||||||
{
|
{
|
||||||
setMinimumSize(0, 0);
|
setMinimumSize(0, 0);
|
||||||
|
@ -333,23 +345,22 @@ QssMainWindow::QssMainWindow(QWidget *parent/* = 0*/, Qt::WindowFlags flags/* =
|
||||||
vbox->setSpacing(0);
|
vbox->setSpacing(0);
|
||||||
vbox->addWidget(this);
|
vbox->addWidget(this);
|
||||||
|
|
||||||
|
|
||||||
mFrameRect = m_frame->geometry();
|
mFrameRect = m_frame->geometry();
|
||||||
m_rcNormal = m_frame->geometry();
|
m_rcNormal = m_frame->geometry();
|
||||||
m_rcNormalCentral = this->geometry();
|
m_rcNormalCentral = this->geometry();
|
||||||
connect(this->titleBar(),SIGNAL( OnMaxOrRestore(bool )),this,SLOT(OnMaxOrRestore(bool)));
|
connect(this->titleBar(),SIGNAL( OnMaxOrRestore(bool )),this,SLOT(OnMaxOrRestore(bool)));
|
||||||
QFile file(":/qss/css/QssMainWindow.css");
|
QFile file(":/qss/css/QssMainWindow.css");
|
||||||
if (!file.open(QIODevice::ReadOnly)){
|
if (!file.open(QIODevice::ReadOnly)){
|
||||||
qDebug()<<"error bar";
|
qDebug()<<"error QssMainWindow.css";
|
||||||
}
|
}
|
||||||
QTextStream in(&file);
|
QTextStream in(&file);
|
||||||
QString css = in.readAll();
|
QString css = in.readAll();
|
||||||
qDebug()<<css;
|
|
||||||
m_frame->setStyleSheet(css);
|
m_frame->setStyleSheet(css);
|
||||||
|
|
||||||
mShadowMask = new QWidget(this);
|
mShadowMask = new QWidget(this);
|
||||||
mShadowMask->setStyleSheet("QWidget{background-color:rgba(1,1,1,0.3);}");
|
mShadowMask->setStyleSheet("QWidget{background-color:rgba(1,1,1,0.3);}");
|
||||||
mShadowMask->hide();
|
mShadowMask->hide();
|
||||||
|
m_frame->setLayout(vbox);
|
||||||
|
this->setFixedHeight(m_rcNormal.height() - m_titleBar->height());
|
||||||
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -416,17 +427,7 @@ void QssMainWindow::showMinimized()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum {
|
|
||||||
TOPLEFT = 11,
|
|
||||||
TOP = 12,
|
|
||||||
TOPRIGHT = 13,
|
|
||||||
LEFT = 21,
|
|
||||||
CENTER = 22,
|
|
||||||
RIGHT = 23,
|
|
||||||
BUTTOMLEFT = 31,
|
|
||||||
BUTTOM = 32,
|
|
||||||
BUTTOMRIGHT = 33
|
|
||||||
};
|
|
||||||
|
|
||||||
void QssMainWindow::setCursorShape(int CalPos)
|
void QssMainWindow::setCursorShape(int CalPos)
|
||||||
{
|
{
|
||||||
|
@ -511,8 +512,7 @@ int QssMainWindow::CalCursorCol(QPoint pt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void QssMainWindow::onMouseMoveEvent(QMouseEvent * ev)
|
void QssMainWindow::onMouseMoveEvent(QMouseEvent * ev) {
|
||||||
{
|
|
||||||
if (m_titleBar->maxOrRestore())
|
if (m_titleBar->maxOrRestore())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -521,12 +521,9 @@ void QssMainWindow::onMouseMoveEvent(QMouseEvent * ev)
|
||||||
{
|
{
|
||||||
setCursorShape(CalCursorPos(ev->pos(),CalCursorCol(ev->pos())));
|
setCursorShape(CalCursorPos(ev->pos(),CalCursorCol(ev->pos())));
|
||||||
}
|
}
|
||||||
QPoint ptCurrentPos = QCursor::pos();
|
|
||||||
QRect rtCentralGeo = this->centralWidget()->geometry();
|
QRect rtCentralGeo = this->centralWidget()->geometry();
|
||||||
QRect rtMainWindow = this->geometry();
|
|
||||||
setCursor(Qt::ArrowCursor);
|
setCursor(Qt::ArrowCursor);
|
||||||
if (m_mousePressedInBoundy)
|
if (m_mousePressedInBoundy) {
|
||||||
{
|
|
||||||
int x = ev->globalPos().x();
|
int x = ev->globalPos().x();
|
||||||
int y = ev->globalPos().y();
|
int y = ev->globalPos().y();
|
||||||
|
|
||||||
|
@ -542,34 +539,45 @@ void QssMainWindow::onMouseMoveEvent(QMouseEvent * ev)
|
||||||
if (m_top && dy > 0 && mFrameRect.height() <= m_frame->minimumHeight())
|
if (m_top && dy > 0 && mFrameRect.height() <= m_frame->minimumHeight())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QRect rc = mFrameRect;
|
QRect layout = this->m_frame->layout()->geometry();
|
||||||
|
QRect frame = this->m_frame->geometry();
|
||||||
|
|
||||||
|
QRect rc = m_rcNormalCentral;
|
||||||
if (m_left){
|
if (m_left){
|
||||||
rc.setLeft(rc.left() + dx);
|
rc.setLeft(rc.left() + dx);
|
||||||
rtMainWindow.setLeft(rtMainWindow.left() + dx);
|
frame.setLeft(frame.left() + dx);
|
||||||
|
layout.setLeft(layout.left() + dx);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (m_right){
|
if (m_right){
|
||||||
rc.setRight(rc.right() + dx);
|
rc.setRight(rc.right() + dx);
|
||||||
rtCentralGeo.setRight(rtCentralGeo.right() + dx);
|
layout.setRight(layout.right() + dx);
|
||||||
rtMainWindow.setRight(rtMainWindow.right() + dx);
|
frame.setRight(frame.right() + dx);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (m_top){
|
if (m_top){
|
||||||
rc.setTop(rc.top() + dy);
|
rc.setTop(rc.top() + dy);
|
||||||
rtCentralGeo.setTop(rtCentralGeo.top() + dy);
|
layout.setTop(layout.top() + dy);
|
||||||
rtMainWindow.setTop(rtMainWindow.top() + dy);
|
frame.setTop(frame.top() + dy);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (m_bottom){
|
if (m_bottom){
|
||||||
rc.setBottom(rc.bottom() + dy);
|
rc.setBottom(rc.bottom() + dy);
|
||||||
rtCentralGeo.setBottom(rtCentralGeo.bottom() + dy);
|
layout.setBottom(layout.bottom() + dy);
|
||||||
rtMainWindow.setBottom(rtMainWindow.bottom() + dy);
|
frame.setBottom(frame.bottom() + dy);
|
||||||
}
|
}
|
||||||
m_frame->setGeometry(rc);
|
setMinimumSize(0, 0);
|
||||||
m_frame->show();
|
setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
|
||||||
|
this->m_frame->setMinimumSize(0, 0);
|
||||||
|
this->m_frame->setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
|
||||||
|
this->parentWidget()->setGeometry(frame);
|
||||||
|
|
||||||
|
// this->setGeometry(m_rcNormalCentral);
|
||||||
mFrameRect = rc;
|
mFrameRect = rc;
|
||||||
m_CentralRect = rtCentralGeo;
|
m_CentralRect = rtCentralGeo;
|
||||||
m_pos = ev->globalPos();
|
m_pos = ev->globalPos();
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
int x = ev->x();
|
int x = ev->x();
|
||||||
int y = ev->y();
|
int y = ev->y();
|
||||||
|
|
||||||
|
@ -738,6 +746,8 @@ void QssMainWindow::showEvent(QShowEvent *ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QssMainWindow::eventFilter(QObject * obj, QEvent * ev){
|
bool QssMainWindow::eventFilter(QObject * obj, QEvent * ev){
|
||||||
|
|
||||||
|
qDebug()<<ev->type()<<obj;
|
||||||
if (ev->type() == QEvent::Hide){
|
if (ev->type() == QEvent::Hide){
|
||||||
qDebug()<<"hide";
|
qDebug()<<"hide";
|
||||||
}
|
}
|
||||||
|
@ -748,6 +758,11 @@ bool QssMainWindow::eventFilter(QObject * obj, QEvent * ev){
|
||||||
if (obj == m_frame)
|
if (obj == m_frame)
|
||||||
{
|
{
|
||||||
if (ev->type() == QEvent::Paint){
|
if (ev->type() == QEvent::Paint){
|
||||||
|
if(m_frame->isHidden()){
|
||||||
|
qDebug()<<"hidden";
|
||||||
|
m_frame->show();
|
||||||
|
}
|
||||||
|
// m_frame->showMaximized();
|
||||||
|
|
||||||
}
|
}
|
||||||
if (ev->type() == QEvent::MouseMove)
|
if (ev->type() == QEvent::MouseMove)
|
||||||
|
@ -781,13 +796,17 @@ bool QssMainWindow::eventFilter(QObject * obj, QEvent * ev){
|
||||||
}
|
}
|
||||||
else if (ev->type() == QEvent::Show)
|
else if (ev->type() == QEvent::Show)
|
||||||
{
|
{
|
||||||
QRect rc = m_frame->rect();
|
m_titleBar->show();
|
||||||
QRect parentRc = m_rcValid;
|
this->showNormal();
|
||||||
|
this->centralWidget()->showNormal();
|
||||||
|
|
||||||
/** m_frame */
|
// QRect rc = m_frame->rect();
|
||||||
int x = parentRc.left() + (parentRc.width() - rc.width())*0.5; x = x <= 0 ? 1 : x;
|
// QRect parentRc = m_rcValid;
|
||||||
int y = parentRc.top() + (parentRc.height() - rc.height())*0.5; y = y <= 0 ? 1 : y;
|
|
||||||
m_frame->move(x, y);
|
// /** m_frame */
|
||||||
|
// int x = parentRc.left() + (parentRc.width() - rc.width())*0.5; x = x <= 0 ? 1 : x;
|
||||||
|
// int y = parentRc.top() + (parentRc.height() - rc.height())*0.5; y = y <= 0 ? 1 : y;
|
||||||
|
// m_frame->move(x, y);
|
||||||
}
|
}
|
||||||
else if (ev->type() == QEvent::Close)
|
else if (ev->type() == QEvent::Close)
|
||||||
{
|
{
|
||||||
|
@ -803,7 +822,7 @@ bool QssMainWindow::eventFilter(QObject * obj, QEvent * ev){
|
||||||
else if (ev->type() == QEvent::Hide)
|
else if (ev->type() == QEvent::Hide)
|
||||||
{
|
{
|
||||||
if(m_tray_on){
|
if(m_tray_on){
|
||||||
m_frame->hide();
|
// m_frame->hide();
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
close();
|
close();
|
||||||
|
@ -1715,6 +1734,7 @@ void QssDockWidget::setWindowTitle(QString title)
|
||||||
|
|
||||||
bool QssDockWidget::eventFilter(QObject *obj, QEvent *ev)
|
bool QssDockWidget::eventFilter(QObject *obj, QEvent *ev)
|
||||||
{
|
{
|
||||||
|
qDebug()<<ev<<obj->objectName();
|
||||||
if (obj == m_frame)
|
if (obj == m_frame)
|
||||||
{
|
{
|
||||||
if (ev->type() == QEvent::MouseMove)
|
if (ev->type() == QEvent::MouseMove)
|
||||||
|
@ -1830,7 +1850,7 @@ bool QssDockWidget::eventFilter(QObject *obj, QEvent *ev)
|
||||||
}
|
}
|
||||||
else if (ev->type() == QEvent::Hide)
|
else if (ev->type() == QEvent::Hide)
|
||||||
{
|
{
|
||||||
m_frame->hide();
|
// m_frame->hide();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue