QLabel * label = new QLabel("Hello!")
label->setAlignment(Qt::AlignRight | Qt::AlignBottom)
Qt::Aligment列表如下:
The horizontal flags are:
Constant Value Description
Qt::AlignLeft 0x0001 Aligns with the left edge.
Qt::AlignRight 0x0002 Aligns with the right edge.
Qt::AlignHCenter 0x0004 Centers horizontally in the available space.
Qt::AlignJustify 0x0008 Justifies the text in the available space.
The vertical flags are:
Constant Value Description
Qt::AlignTop 0x0020 Aligns with the top.
Qt::AlignBottom 0x0040 Aligns with the bottom.
Qt::AlignVCenter 0x0080 Centers vertically in the available space.
You can use only one of the horizontal flags at a time. There is one two-dimensional flag:
Constant Value Description
Qt::AlignCenter AlignVCenter | AlignHCenter Centers in both dimensions.
void MainWindow::createStatusBar(){
locationLabel = new QLabel(" W999 ")//以文字" W999 " 建立 一个新的QLabel的对象
locationLabel->setAlignment(Qt::AlignHCenter)//文字对齐方式为中间对齐
locationLabel->setMinimumSize(locationLabel->sizeHint())
//设置这个Label的最小大小为当前最适合的大小。即Label的最小面积就是现在的大小了
formulaLabel = new QLabel
formulaLabel->setIndent(3)
//设置自动缩进
statusBar()->addWidget(locationLabel)
statusBar()->addWidget(formulaLabel, 1)
//第二个参数是设置 窗体 伸张系数的,默认为0.
connect(spreadsheet, SIGNAL(currentCellChanged(int, int, int, int)),
this, SLOT(updateStatusBar()))
connect(spreadsheet, SIGNAL(modified()),
this, SLOT(spreadsheetModified()))
updateStatusBar()
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)