
{
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()
}
#ifndef WIDGET_H#define WIDGET_H
#include <QtGui/QWidget>
#include <QPushButton>
#include <QLabel>
#include <QHBoxLayout>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0)
~Widget()
QPushButton *clearNO,*addNO
QLabel *label
QHBoxLayout *qhboxlayout
private slots:
void clearNOhandle()
void addNOhandle()
}
#endif // WIDGET_H
///////////widget.cpp
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
clearNO =new QPushButton("CLEAR")
addNO =new QPushButton("ADD")
label =new QLabel("0")
qhboxlayout =new QHBoxLayout(this)
qhboxlayout->addWidget(label)
qhboxlayout->addWidget(clearNO)
qhboxlayout->addWidget(addNO)
connect(clearNO,SIGNAL(clicked()),this,SLOT(clearNOhandle()))
connect(addNO,SIGNAL(clicked()),this,SLOT(addNOhandle()))
}
void Widget::addNOhandle(){
QString nostr
int no
nostr = label->text()
no = nostr.toInt()
no++
nostr.setNum(no)
label->setText(nostr)
}
////////main函数
void Widget::clearNOhandle(){
label->setText("0")
}
Widget::~Widget()
{
}
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv)
Widget w
w.show()
return a.exec()
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)