[求助]QT4 ScrollView中嵌套Q3GridLayout,显示异常问题

执一终始 2018-01-23 09:44:52
SCrollView中放一个Widget,Widget放入一个Q3GridLayout,然后再在这个GridLayout中放入多个GridLayout,多个GridLayout中每个放入多个固定高度的Label,这时出现了Label边界重叠的情况,如果取消Label的固定高度,就不会重叠,求指导,附上代码和图,新手勿喷

#include "Q3test.h"
#include <qdatetime.h>
#include <Q3TextStream>
#include <QLabel>
#include <Q3GridLayout>
#include <Q3Frame>
#include <Q3PopupMenu>
#include <QMouseEvent>
#include <QEvent>
#include <Q3ScrollView>
using namespace std;
Q3test::Q3test(QDialog* parent, const char* name):QDialog(parent,name)//,
//ui(new Ui::MainWindow)
{
//setupUi(this);
vector<Q3GridLayout*> layoutvec;
vector<QWidget*> layoutv;
Q3Frame* myFrame=new Q3Frame(NULL);
Q3ScrollView* scrollview=new Q3ScrollView(this);
scrollview->addChild(myFrame,0,0);
scrollview->resizeContents(100,100);
//scrollview->enableClipper(true);
scrollview->viewport()->setBackgroundMode(Qt::PaletteBackground);
scrollview->setFrameShape(Q3Frame::NoFrame);
Q3GridLayout *mylayout=new Q3GridLayout(this,2,5,0,0);
QLabel * showtypeLabel = new QLabel( this, "showtypeLabel" );
showtypeLabel = new QLabel( this, "showtypeLabel" );
showtypeLabel->setText(QString("xxxxxhello"));
showtypeLabel->setGeometry( QRect( 40, 30, 81, 29 ) );
showtypeLabel->setPaletteForegroundColor( QColor( 255, 255, 255 ) );
mylayout->addWidget( showtypeLabel,0,0);
//mylayout->addWidget( showtypeLabel,0,0);
// mylayout->addWidget( showtypeComboBox,0,1);
// mylayout->addWidget( configButton,0,2);
// mylayout->addItem( spacer1, 0, 3 );
mylayout->addMultiCellWidget(scrollview,1,1,0,4);
Q3GridLayout * grid2=new Q3GridLayout(myFrame,13,1,0,0);
for(int si=0;si<13;si++)
{
//QWidget * qw =new QWidget();
Q3GridLayout * grid1=new Q3GridLayout(0,5,1,0,0);
for(int sj=0;sj<3;sj++)
{
QLabel * labelt=new QLabel();
labelt->setText("hello");
labelt->setFrameShape(Q3Frame::Box);
labelt->setFixedHeight(60);
grid1->setRowMinimumHeight(sj,40);
grid1->addMultiCellWidget(labelt,sj,sj,0,0,Qt::AlignLeft);
//grid1->addWidget(labelt,sj,0);
}
layoutvec.push_back(grid1);
//layoutv.push_back(qw);
//grid2->addMultiCellWidget(*grid1,si,0,0,0,Qt::AlignLeft);
}
grid2->addMultiCellLayout(layoutvec[1],1,1,0,0,Qt::AlignVCenter);
for(uint i=0;i<layoutvec.size();i++)
{
//grid2->addWidget(layoutv[i],i,0,1,1,Qt::AlignVCenter);
grid2->addMultiCellLayout(layoutvec[i],i,i,0,0,Qt::AlignVCenter);
}
//resize((myFrame->height()+30<=600)?myFrame->width():myFrame->width()+16,min(myFrame->height()+46,600));

}
Q3test::~Q3test()
{

}
int Q3test::init()
{

}
...全文
1465 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
donwmufromdying 2018-01-26
  • 打赏
  • 举报
回复
你固定高低或者宽度后,如果两个label宽度超过layout的就一定会重叠.这个你在designer里自己画画看就知道了.
执一终始 2018-01-23
  • 打赏
  • 举报
回复


重叠

16,199

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧