QT Designer学习教程

移动开发
本文介绍的是QT Designer学习教程,QT Designer相信友们并不是很陌生,那么先来看本文详细讲解吧。

QT Designer学习教程 是本文要介绍的内容,不多说,先来看内容。好的,现在我们一起来学习使用 QT Designer 设计我们的QT应用程序。

现在我们做一些准备工作,我们最好为每一个QT程序建立一个单独的文件夹,这样就可以让我们更方便的使用QT为我们提供的工具,例如qmake等。

[root@localhost test]# mkdir /root/DesignerTutorial1  
[root@localhost test]# cd /root/DesignerTutorial1 
  • 1.
  • 2.

然后打开 QT Designer ,直接在命令行下输入:designer,如下:

[root@localhost DesignerTutorial1]# designer&  
[3] 16544  
[root@localhost DesignerTutorial1]# 
  • 1.
  • 2.
  • 3.

这里我们看到"Qt Designer - New/Open"对话框,这是一个新建对话框,我们可以通过从菜单栏的 File->New 来打开它。

我们先选择对话框上的第一个"C++ Project",确定,然后更改名字,这里我们改为 tutorial1.pro 保存,默认情况是保存到我们刚刚创建的文件夹 /root/DesignerTutorial1,这样我们就创建了一个 *.pro 文件。下面我们再创建一个对话框。

从菜单栏的 File->New 打开新建对话框,选择第二个:Dialog,然后也同样保存到刚刚创建的文件夹 /root/DesignerTutorial1 下。

这时侯,你的 QT Designer 中就会出现一个 From1 来. 更改右下角那个窗口里的 caption ,原内容 "Form1"改为 "我的第一个QT Desiger程序"

name     
内容 "Form1"改为 "form_main" 
  • 1.
  • 2.

可以看到这时候窗口的标题栏文字已经改变为"Form1"改为 "我的第一个QT Desiger程序",不是吗?

现在我们点击一下左边窗口上面的 ToolBox 中的那个 PushButton (标有 OK 的图标)并且用鼠标选择一个合适的大小. 在这个 PushButton 上面用用鼠标双击一下,我们就可以改变按钮上显示的字了。

这里我们把"pushButton1"这几个字,换成 “Hello World!”, 然後用选择 OK 就可以了. 现在我们看到, 那个按钮上的标签已将变成 “Hello World!” 了. 更改右下角那个窗口"Property Editor"里的 name  , 原内容 "pushButton1"改为 "pBtnHello"我们就算是基本完成了。

保存下。 如果想看看这个小程序长什麽样子.可以用 CTRL+T来看 PreView. 这时侯我们只需要一个小的 main.cpp 就可以编译了。同样我们的 QT Designer 也可以为我们生成 main.cpp 。

从菜单栏的 File->New 打开新建对话框,选择最后一个:C++ Main-File(main.cpp).

然后也同样保存到刚刚创建的文件夹 /root/DesignerTutorial1 下。

好了,现在来编译我们的程序。

生成Makefile文件:

[root@localhost DesignerTutorial1]# qmake 
  • 1.

编译:

[root@localhost DesignerTutorial1]# make  
/usr/lib/qt-3.1/bin/uic form1.ui -o .ui/form1.h  
g++  
-c -pipe -Wall -W -O2 -march=i386 -mcpu=i686 -g -DGLX_GLXEXT_LEGACY  
-fno-use-cxa-atexit -fno-exceptions  -DQT_NO_DEBUG  
-I/usr/lib/qt-3.1/mkspecs/default -I. -I/usr/lib/qt-3.1/include -I.ui/  
-I.moc/ -o .obj/main.o main.cpp  
/usr/lib/qt-3.1/bin/uic form1.ui -i form1.h -o .ui/form1.cpp  
g++  
-c -pipe -Wall -W -O2 -march=i386 -mcpu=i686 -g -DGLX_GLXEXT_LEGACY  
-fno-use-cxa-atexit -fno-exceptions  -DQT_NO_DEBUG  
-I/usr/lib/qt-3.1/mkspecs/default -I. -I/usr/lib/qt-3.1/include -I.ui/  
-I.moc/ -o .obj/form1.o .ui/form1.cpp  
/usr/lib/qt-3.1/bin/moc .ui/form1.h -o .moc/moc_form1.cpp  
g++  
-c -pipe -Wall -W -O2 -march=i386 -mcpu=i686 -g -DGLX_GLXEXT_LEGACY  
-fno-use-cxa-atexit -fno-exceptions  -DQT_NO_DEBUG  
-I/usr/lib/qt-3.1/mkspecs/default -I. -I/usr/lib/qt-3.1/include -I.ui/  
-I.moc/ -o .obj/moc_form1.o .moc/moc_form1.cpp  
g++  -o tutorial1 .obj/main.o .obj/form1.o .obj/moc_form1.o  -L/usr/lib/qt-3.1/lib -L/usr/X11R6/lib -lqt-mt -lXext -lX11 -lm  
[root@localhost DesignerTutorial1]# ls  
form1.ui  form1.ui~  main.cpp  Makefile  tutorial1  tutorial1.pro 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.

可以看到 tutorial1 ,这就是我们的可执行程序,

运行:

[root@localhost DesignerTutorial1]# ./tutorial1 
  • 1.

大功告成。

总结:关于QT Designer学习教程 的内容介绍完了,这里我们学习了在LinuxQT Designer 的基本使用方法,并且了解了QT程序的编译方法,很简单,不是吗?最后希望本文对你有所帮助!

责任编辑:zhaolei 来源: 互联网
相关推荐

2011-07-04 11:29:40

QT Designer

2011-06-27 16:07:49

Qt Designer

2011-06-27 16:37:08

Qt Designer

2011-06-27 16:18:24

Qt Designer

2011-07-04 13:17:18

Qt Designer 布局

2011-07-04 13:26:30

Qt Designer

2011-07-04 13:08:26

Qt Designer

2011-06-27 14:56:46

Qt Designer

2011-06-13 14:29:40

Qt Designer

2011-06-10 11:24:08

Qt Quick Designer

2011-08-30 15:32:08

QtQuickQML

2011-09-07 16:28:46

QT WidgetQWidget

2011-06-28 17:13:46

Qt Designer UI

2011-08-30 15:49:03

QtQuick

2011-09-01 16:01:25

Qt插件

2011-06-13 15:09:36

插件 Qt Designer

2011-06-13 14:49:57

Qt Designer

2011-06-13 14:00:55

Qt Designer linux

2011-06-20 15:52:14

Qt Designer 控件

2011-07-04 14:29:25

Qt Designer 容器
点赞
收藏

51CTO技术栈公众号