Qt 双向qspliter
我想制作一个包含四个小部件的应用程序,这些小部件可以使用QSplitter调整大小。在这个应用程序中,我希望当我调整拆分器的大小时,所有四个小部件都被调整大小。我意识到这一点,有一个水平分离器包含两个垂直分离器。然而,通过这种方式,垂直拆分只涉及两个小部件,而不是全部四个。有没有办法实现这种“矩阵”拆分?您是否尝试过将其中一个的Qt 双向qspliter,qt,qsplitter,Qt,Qsplitter,我想制作一个包含四个小部件的应用程序,这些小部件可以使用QSplitter调整大小。在这个应用程序中,我希望当我调整拆分器的大小时,所有四个小部件都被调整大小。我意识到这一点,有一个水平分离器包含两个垂直分离器。然而,通过这种方式,垂直拆分只涉及两个小部件,而不是全部四个。有没有办法实现这种“矩阵”拆分?您是否尝试过将其中一个的splitterMoved(int,int)信号连接到另一个的moveSplitter(int,int)插槽 QObject::connect(ui->upperS
splitterMoved(int,int)
信号连接到另一个的moveSplitter(int,int)
插槽
QObject::connect(ui->upperSplitter, SIGNAL(splitterMoved(int,int), ui->lowerSplitter, SLOT(moveSplitter(int,int));
QObject::connect(ui->lowerSplitter, SIGNAL(splitterMoved(int,int), ui->upperSplitter, SLOT(moveSplitter(int,int));
或者您可能需要查看qspliterHandle类
希望这会有所帮助。另一种可能的答案是手动布局,在四个小部件的交叉处有一个奇特的大小调整手柄 应该使用鼠标事件和setGeometry调用使用几行代码来完成 如下(工作示例): (只需添加一个绘制事件,即可在中心绘制控制柄) 该死。。显然,这是按钮标签的复制粘贴错误;)我修正了密码
FourWaySplitter::FourWaySplitter(QWidget*父项):
QWidget(母公司),
ui(新ui::FourWaySplitter),m_边距(5)
{
用户界面->设置用户界面(此);
m_ul=新的QPushButton(“左上角”,此按钮);
m_ur=新的QPushButton(“右上角”,该按钮);
m_ll=新的QPushButton(左下角,此按钮);
m_lr=新的QPUSH按钮(“右下”,此按钮);
设置固定宽度(500);
设置固定高度(400);
//当然,需要以合理的方式更新以下内容
//当“this”在“resizeEvent(QResizeEvent*)”处理程序中不是固定大小时
m_handleCenter=rect().center();
m_ul->setGeometry(QRect(QPoint(m_margin,m_margin),m_handleCenter-QPoint(m_margin,m_margin));
m_-ur->setGeometry(QRect(QPoint(width()/2+m_-margin,m_-margin),QPoint(width()-m_-margin,height()/2-m_-margin));
m_ll->setGeometry(QRect(QPoint(m_margin,height()/2+m_margin),QPoint(width()/2-m_margin,height()-m_margin));
m_lr->setGeometry(qect(QPoint(宽度()/2+m_边距,高度()/2+m_边距),QPoint(宽度()-m_边距,高度()-m_边距));
}
void FourWaySplitter::mouseMoveEvent(QMouseEvent*e)
{
if(m_mouseMove){
QRect newGeo=m_ul->geometry();
newGeo.setBottomRight(e->pos()+QPoint(-m_-margin,-m_-margin));
m_ul->setGeometry(newGeo);
newGeo=m_ur->geometry();
newGeo.setBottomLeft(e->pos()+QPoint(+m_边距,-m_边距));
m_ur->setGeometry(newGeo);
newGeo=m_ll->geometry();
newGeo.setTopRight(e->pos()+QPoint(-m_margin,+m_margin));
m_ll->setGeometry(newGeo);
newGeo=m_lr->geometry();
newGeo.setTopLeft(e->pos()+QPoint(+m_边距,+m_边距));
m_lr->setGeometry(newGeo);
}
}
void FourWaySplitter::mousePressEvent(QMouseEvent*e)
{
如果((e->pos()-m_handleCenter).曼哈顿长度()<10){
m_mouseMove=true;
}
}
void FourWaySplitter::mouseReleaseEvent(QMouseEvent*e)
{
m_handleCenter=rect().center();
m_mouseMove=false;
}
FourWaySplitter::~FourWaySplitter()
{
删除用户界面;
}
希望这不会导致循环信号。。但这是个好主意。不幸的是,moveSplitter不是插槽,所以您编写的行无法工作。无论如何,您可以创建自己的插槽并在那里调用moveSplitter
FourWaySplitter::FourWaySplitter(QWidget *parent) :
QWidget(parent),
ui(new Ui::FourWaySplitter), m_margin(5)
{
ui->setupUi(this);
m_ul = new QPushButton("Upper Left", this);
m_ur = new QPushButton("Upper Right", this);
m_ll = new QPushButton("Lower Left", this);
m_lr = new QPushButton("Lower Right", this);
setFixedWidth(500);
setFixedHeight(400);
// of course, the following needs to be updated in a sensible manner
// when 'this' is not of fixed size in the 'resizeEvent(QResizeEvent*)' handler
m_handleCenter = rect().center();
m_ul->setGeometry(QRect(QPoint(m_margin,m_margin), m_handleCenter - QPoint(m_margin, m_margin)));
m_ur->setGeometry(QRect(QPoint(width()/2 + m_margin, m_margin), QPoint(width() - m_margin, height()/2 - m_margin)));
m_ll->setGeometry(QRect(QPoint(m_margin, height()/2 + m_margin), QPoint(width()/2 - m_margin, height() - m_margin)));
m_lr->setGeometry(QRect(QPoint(width()/2 + m_margin, height()/2 + m_margin), QPoint(width() - m_margin, height() - m_margin)));
}
void FourWaySplitter::mouseMoveEvent(QMouseEvent * e)
{
if(m_mouseMove) {
QRect newGeo = m_ul->geometry();
newGeo.setBottomRight(e->pos() + QPoint(-m_margin, -m_margin));
m_ul->setGeometry(newGeo);
newGeo = m_ur->geometry();
newGeo.setBottomLeft(e->pos() + QPoint(+m_margin, -m_margin));
m_ur->setGeometry(newGeo);
newGeo = m_ll->geometry();
newGeo.setTopRight(e->pos() + QPoint(-m_margin, + m_margin));
m_ll->setGeometry(newGeo);
newGeo = m_lr->geometry();
newGeo.setTopLeft(e->pos() + QPoint(+m_margin, + m_margin));
m_lr->setGeometry(newGeo);
}
}
void FourWaySplitter::mousePressEvent(QMouseEvent * e)
{
if((e->pos() - m_handleCenter).manhattanLength() < 10) {
m_mouseMove = true;
}
}
void FourWaySplitter::mouseReleaseEvent(QMouseEvent * e)
{
m_handleCenter = rect().center();
m_mouseMove = false;
}
FourWaySplitter::~FourWaySplitter()
{
delete ui;
}