QT编程如何在一个qmainwindow窗口顶部加一个label呀,就是跟窗口标题在一行的 50
1个回答
2015-06-14 · 知道合伙人互联网行家
关注
展开全部
#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();
}
#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();
}
追问
不是这样的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询