Qt入门

// 这里我们只显示 ok_one 和 ok_two, 简单的来说,就是显示 radio button
// 和 check box 的状态一共被检查过几次

picture = new QLabel (this, "picture");
picture->setGeometry (QRect (480, 10, 110, 140));
picture->setText (tr ("Picture"));

QPixmap pixmap ("logo.xpm");
picture->setPixmap (pixmap);
picture->setScaledContents (TRUE);

// 我用 convert 这苹程式,把那个企鹅的 logo (logo.gif) 转换成了 logo.xpm
// 这里我们把这个 loggo 读进来. 并且让 picture 这个 QLabel 作为我们的显示
// 对象. 这样我们的程式里面就有了一苹象徵 Linix 的小企鹅了.

LineEdit = new QLineEdit (this, "LineEdit");
LineEdit->setGeometry (QRect (210, 30, 251, 51));
LineEdit->setReadOnly (TRUE);

// 我们这里用 lineedit 用来显示 radio button
// 所以我们把 LineEdit 设定为 setReadOnly (TRUE) 只读

MultiLineEdit = new QMultiLineEdit (this, "MultiLineEdit");
MultiLineEdit->setGeometry (QRect (210, 150, 250, 90));
MultiLineEdit->setReadOnly (TRUE);

// 我们用 MultiLineEdit 来显示 check box 的状态
// 同样的道理,这里我们也无需输入,所以设定 MultiLineEdit 为只读

LCD = new QLCDNumber (this, "LCD");
LCD->setGeometry (QRect (220, 320, 231, 91));
LCD->setNumDigits (10);
LCD->setProperty ("intValue", 0);

// 因为考虑到我们会使用 bin (二进位)的方法来显示
// 所以把显示的最大位配置为 10 位 LCD->setNumDigits (10)
// 并且设定初始值为 0
// LCDNumber 的内定显示是 DEC 的. (十进位)

group_three = new QButtonGroup (this, "group_three");
group_three->setGeometry (QRect (470, 170, 111, 221));
group_three->setTitle (tr ("LCD"));

dec = new QRadioButton (group_three, "dec");
dec->setGeometry (QRect (10, 60, 81, 21));
dec->setText (tr ("Dec"));
dec->setChecked (TRUE);

oct = new QRadioButton (group_three, "oct");
oct->setGeometry (QRect (10, 90, 81, 31));
oct->setText (tr ("OTC"));

bin = new QRadioButton (group_three, "bin");
bin->setGeometry (QRect (10, 120, 91, 31));
bin->setText (tr ("Bin"));

hex = new QRadioButton (group_three, "hex");
hex->setGeometry (QRect (10, 30, 81, 21));
hex->setText (tr ("Hex"));

lcd_ok_button = new QPushButton (group_three, "lcd_ok_button");
lcd_ok_button->setGeometry (QRect (10, 160, 91, 51));
lcd_ok_button->setText (tr ("OK"));

// 在 LCD 旁边再建立一个 group ( Button Group ) 里面包含了 radio button 和 bush button
// radio button 有 dec, oct, bin, hex 这四项. 用来选择 LCD 的显示模式 (8进位,10进位,16进位,2进位)
// lcd_ok_button 是个 push button. 最为选择 LCD 显示模式的 『确定』键


clear_button = new QPushButton (this, "cler_button");
clear_button->setGeometry (QRect (10, 420, 131, 41));
clear_button->setText (tr ("Clear All"));

// 这个显示为 clear all 的 push button, 用来把
// 任何的值都设定到原始状态

exit_button = new QPushButton (this, "exit_button");
exit_button->setGeometry (QRect (430, 420, 131, 41));
exit_button->setText (tr ("Exit"));

// 退出程式用的 push button

connect (ok_one, SIGNAL (clicked ()), this, SLOT (check_radio ()));
// 连接一个信号,假如 ok_one 被 click 了,就去执行 check_radio()

connect (ok_two, SIGNAL (clicked ()), this, SLOT (check_box ()));
// 连接一个信号,假如 ok_two 被 click 了, 就去执行 check_box()

connect (lcd_ok_button, SIGNAL (clicked ()), this, SLOT (check_lcd ()));
// 连接一个信号,假如 lcd_ok_button 被 click 了,就去执行 check_lcd()

connect (clear_button, SIGNAL (clicked ()), this, SLOT (CLEAR ()));
// 连接一个信号,假如 clear_button 被 click 了,就去执行 CLEAR ()

connect (exit_button, SIGNAL (clicked ()), kapp, SLOT (quit ()));
// 连接一个信号,假如 exit_button 被 click 了, 就把我们的整个程式关闭掉
}

Final::~Final () //
{

}

void Final::check_radio ()
{
i ;
if (radio_one->isChecked ())
LineEdit->setText (tr ("Radio Button 1 is Checked"));
if (radio_two->isChecked ())
LineEdit->setText (tr ("Radio Button 2 is Checked"));
LCD->display (i);
}
// 在 check_radio () 中.我们用 isCheck() 来检查 radio button 的状态
// 假如 radio button 是被选择的,那麽 isCheck() 将会返回 TRUE
// 假如 radio button 没有被选择,则返回 FALSE 的值
// 假如说 radio_one 有被选择,我们就用 setText() 在 LineEdit 中显示 Radio Button 1 is Clicked
// 这几个字
// 假如 radio_two 有被选择,我们就用 setText() 在 LineEdit 中显示 Radio Button 2 is Clicked

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值