当前位置: 代码迷 >> QT开发 >> button 显示不出来,只显示一个主框,要如何解决?
  详细解决方案

button 显示不出来,只显示一个主框,要如何解决?

热度:82   发布时间:2016-04-25 04:58:31.0
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指当前窗口,就是按钮的父控件
  相关解决方案