读书人

button 显示不出来只显示一个主框

发布时间: 2012-03-17 19:06:28 作者: rapoo

button 显示不出来,只显示一个主框,要怎么解决???
为什么btn1 显示不出来???

main.cpp

#include "iphone.h"
#include <QApplication>


int main(int argc, char *argv[])
{
//Q_INIT_RESOURCE(application);

QApplication app(argc, argv);
//Iphone *iphone = new Iphone();
//iphone->show();
Iphone iphone;
iphone.show();
return app.exec();
}





iphone.h

#ifndef _IPHONE_H_
#define _IPHONE_H_

#include <QDialog>
#include <QPushButton>
#include <QLineEdit>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QPixmap>


class Iphone : public QDialog
{
Q_OBJECT

public:
Iphone(QWidget *parent = 0);
~Iphone();
void create_btn(void);
private:

QPushButton *btn1;
QPushButton *btn2;
QPushButton *btn3;
QPushButton *btn4;
QPushButton *btn5;
QPushButton *btn6;
QPushButton *btn7;
QPushButton *btn8;
QPushButton *btn9;
QPushButton *btn_asterisk;
QPushButton *btn0;
QPushButton *btn_well;
QPushButton *cancle_one;
QPushButton *dialing;
QPushButton *cancle_all;


QVBoxLayout *mainLayout;

};



#endif








iphone.cpp

#include <iphone.h>

Iphone::Iphone(QWidget *parent):QDialog(parent)
{
create_btn();
resize(240,320);
}

Iphone::~Iphone()
{
}

void Iphone::create_btn(void)
{
btn1 = new QPushButton(tr("1")); //这边的btn1 显示不出来???????????
btn1->setGeometry(10,70,70,35);

}

[解决办法]
btn = new QPushButton(this);//this指当前窗口,就是按钮的父控件
[解决办法]

探讨

btn = new QPushButton(this);//this指当前窗口,就是按钮的父控件

读书人网 >QT开发

热点推荐