QT 布局顶行显示
代码如下,感觉没有什么问题,可是label为什么不顶行显示,总是从底部开始呢,请问下为什么?
#include "widget.h"
#include <QHBoxLayout>
#include <QLabel>
#include <QDesktopWidget>
#include <QApplication>
#include <QMessageBox>
#include <QTimer>
#include <QGridLayout>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
setWindowFlags(Qt::FramelessWindowHint); //设置无windows标题
setFixedSize(160,40);
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
timer=new QTimer;
connect(timer,SIGNAL(timeout()),this,SLOT(closewidget()));
timer->start(5000);
grpWidget=new QGroupBox;
QHBoxLayout *rowGrpWin=new QHBoxLayout;
rowGrpWin->setContentsMargins(0,0,0,0);
rowGrpWin->setMargin(0);
label=new QLabel(QObject::tr("set success!")); //就是想把label显示出来,外面套个groupbox
rowGrpWin->addWidget(label);
grpWidget->setLayout(rowGrpWin);
QGridLayout *rowWin=new QGridLayout;
rowWin->setContentsMargins(0,0,0,0);
rowWin->addWidget(grpWidget,0,0);
setLayout(rowWin);
}
Widget::~Widget()
{
}
void Widget::closewidget()
{
timer->stop();
close();
}
请教下,为什么label不是顶行显示呢,谢谢了
[解决办法]
voidsetAlignment ( Qt::AlignTop )