Live instyle

another way to remember...

Subscribe to RSS feed

zz 修改QT Designer设计的界面生成的文件

【原创】学习QT4初步编程(二)

QT4已经发布,与以前的版本有些区别,以及在编程方式上也有区别。
这里以QT4 OpenSource版本为例讲解说明

基于原来的帖子”学习QT4初步编程"
中我使用了修改QT Designer设计的界面生成的文件的方法,引起初学者的一些疑问,会引起初学者以为QT编程这么麻烦的感觉。这里,我采用QT官方发布的例子的编程模式来进行解说。


这个例子和上个例子差不多,只是某些开发模式变了一下。尤其是使用QT Designer生成的界面上面。

首先,我们用QT Designer设计一个界面,如下:
form.ui
QUOTE:

<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>FormEx</class>
<widget class="QWidget" name="FormEx" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>5</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle" >
<string>QT 4.0.1 Test Example</string>
</property>
<widget class="QWidget" name="" >
<property name="geometry" >
<x>10</x> <y>260</y> <width>398</width> <height>25</height>
</property>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="PushButtonInsert" >
<property name="text" >
<string>&Insert</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="PushButtonClear" >
<property name="text" >
<string>&Clear</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>71</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="PushButtonQuit" >
<property name="text" >
<string>&Quit</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QListWidget" name="ListWidgetContent" >
<property name="geometry" >
<x>9</x> <y>9</y> <width>398</width> <height>208</height>
</property>
</widget>
<widget class="QLineEdit" name="LineEditInsert" >
<property name="geometry" >
<x>10</x> <y>230</y> <width>398</width> <height>18</height>
</property>
</widget>
</widget>
<pixmapfunction></pixmapfunction>
<resources/>
<connections>
<connection>
<sender>PushButtonQuit</sender>
<signal>clicked()</signal>
<receiver>FormEx</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel" >
<x>356</x>
<y>265</y>
</hint>
<hint type="destinationlabel" >
<x>348</x>
<y>236</y>
</hint>
</hints>
</connection>
<connection>
<sender>PushButtonClear</sender>
<signal>clicked()</signal>
<receiver>ListWidgetContent</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel" >
<x>203</x>
<y>259</y>
</hint>
<hint type="destinationlabel" >
<x>201</x>
<y>140</y>
</hint>
</hints>
</connection>
</connections>
</ui>


然后,我们新建一个类,来与上面生成的界面结合使用
mywindow.h
QUOTE:

#ifndef MYWINDOW_H
#define MYWINDOW_H

#include <QDialog>
#include "ui_form.h"

class MyWindow:public QDialog, public Ui::FormEx
{
Q_OBJECT
public:
MyWindow(QWidget *parent = 0);
~MyWindow();
public slots:
void InsertItem();
};

#endif

在上面的头文件代码中,我们要说一下,它的使用QT Designer生成的form.ui文件的方式。
#include "ui_form.h"
这个"ui_form.h"文件并不存在,它是在编译的时候,由form.ui生成的一个头文件,
还有它的类名FormEx,这个是由用户在设计界面的时候,设置的,默认为Form或者其它的默认的名字(设计时选择的是MainWindow/Dialog/Widget方式而定,这里用的是Widget),还有前面的Ui::,这个是名字空间,FormEx是定义在名字空间Ui中的。
这里的模式,采用的是多重继承的方式,从QDialog和Ui::FormEx两个类来继承出来我们使用的类。还有一种方式在"如何修改自动生成的.h文件"一贴中说明过了,就是使用单继承,而把FormEx类在类内部声明使用。

mywindow.cpp
QUOTE:

#include <QMessageBox>
#include "mywindow.h"

MyWindow::MyWindow(QWidget *parent): QDialog(parent)
{
setupUi(this); // 这句很重要,这是Ui::FormEx类提供的一个方法,用于不界面中设计的元素都生成。
connect(PushButtonInsert, SIGNAL(clicked()), this, SLOT(InsertItem()));
}

MyWindow::~MyWindow()
{
}

void MyWindow::InsertItem()
{
if (LineEditInsert->text().isEmpty())
{
QMessageBox::critical(this, tr("Error"), tr("the input text box has no character"), QMessageBox::Ok, 0);
}
else
{
ListWidgetContent->addItem(LineEditInsert->text());
LineEditInsert->clear();
}
LineEditInsert->setFocus();
}


好了,下面我们来写main函数:
main.cpp
QUOTE:

#include <QApplication>
#include <QTranslator>
#include "mywindow.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTranslator translator;
translator.load(QString(argv[1]));
app.installTranslator(&translator);
MyWindow mywindow;
return mywindow.exec();
}

好了,现在就可以进行编译了。
我们运行如下命令:
QUOTE:

qmake -project
qmake
make all

上面的make all这是要生成 Debug和Release版,如果要生成单一版本,比如make release,生成release版
注意那句QTranslator....,这里要用到翻译文件,也就是程序的多国语言支撑。
好,下面我们生成多国语言支撑文件
// 这句话是根据.cpp, .h, .ui文件中的信息,生成多国语言支撑的原始文件
QUOTE:

lupdate *.cpp *.h *.ui -ts ex32.ts

接下来,我们就可以使用QT Linguist来进行翻译了。
打开QT Linguist后,用它把ex32.ts打开,就能进行翻译了。
翻译完了每种语言后,用菜单的"release"功能,把它保存为*.qm文件。
我们这里需要三种语言,分别是英文(en),简体中文(zh_CN)和繁体中文(zh_TW)
我们把这三个文件拷贝到可执行文件目录下面(release或debug),然后就能运行了
QUOTE:

ex32 en
ex32 zh_Cn
ex32 zh_TW

上面的三个命令,分别是英文版,简体中文和繁体中文版。
下面的附件是源文件,可执行文件的打包(Win32版的)


[ 此贴被XChinux在2005-08-21 18:21重新编辑 ]


附件: ex32.rar (25 K) 下载次数:498

Important lib in Linux system

linux-gate.so.1 => (0xffffe000)
libqt-mt.so.3 => /usr/lib/qt/lib/libqt-mt.so.3 (0xb78be000)
libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0xb7898000)
libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0xb77ce000)
libpthread.so.0 => /lib/tls/libpthread.so.0 (0xb77bc000)
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0xb7704000)
libm.so.6 => /lib/tls/libm.so.6 (0xb76e1000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0xb76d8000)
libc.so.6 => /lib/tls/libc.so.6 (0xb75a8000)
libmng.so.1 => /usr/lib/libmng.so.1 (0xb754e000)
libjpeg.so.62 => /usr/lib/libjpeg.so.62 (0xb7531000)
libpng.so.3 => /usr/lib/libpng.so.3 (0xb7500000)
libz.so.1 => /usr/lib/libz.so.1 (0xb74ee000)
libGL.so.1 => /usr/lib/libGL.so.1 (0xb7469000)
libXmu.so.6 => /usr/X11R6/lib/libXmu.so.6 (0xb7452000)
libXrender.so.1 => /usr/X11R6/lib/libXrender.so.1 (0xb744a000)
libXrandr.so.2 => /usr/X11R6/lib/libXrandr.so.2 (0xb7447000)
libXcursor.so.1 => /usr/X11R6/lib/libXcursor.so.1 (0xb743e000)
libXinerama.so.1 => /usr/X11R6/lib/libXinerama.so.1 (0xb743b000)
libXft.so.2 => /usr/X11R6/lib/libXft.so.2 (0xb7429000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0xb73b7000)
libfontconfig.so.1 => /usr/X11R6/lib/libfontconfig.so.1 (0xb7390000)
libSM.so.6 => /usr/X11R6/lib/libSM.so.6 (0xb7388000)
libICE.so.6 => /usr/X11R6/lib/libICE.so.6 (0xb7370000)
libdl.so.2 => /lib/tls/libdl.so.2 (0xb736c000)
/lib/ld-linux.so.2 (0xb7f85000)
libGLcore.so.1 => /usr/lib/libGLcore.so.1 (0xb6ba9000)
libnvidia-tls.so.1 => /usr/lib/tls/libnvidia-tls.so.1 (0xb6ba7000)
libXt.so.6 => /usr/X11R6/lib/libXt.so.6 (0xb6b56000)
libexpat.so.0 => /usr/lib/libexpat.so.0 (0xb6b36000)

串口小样

In Columns there are data received from serial port
Click Send Button to Send specific Control signal to achieve this job

linux 下Qt 3安装qwt插件


版本qwt-4.2.0.tar.bz2
解压之后按其中的INSTALL文件安装
#Builds for Qt 3.x need qmake, that is official part of Qt 3.x.
qmake qwt.pro
make
The designer plugin is available for Qt > 3.x only. You can build and
install it with(这个东西编出来在qwt-4.2.0/designer/plugins/designer里生成libqwtplugin.so):

cd designer
qmake qwtplugin.pro
make
make install(这个命令把libqwtplugin.so这个插件库安装在QTDIR/plugins/designer/里,等designer运行的时候就会自动加载qwt了)

If you like to build the examples:
cd examples
qmake examples.pro
make

If you like to run the examples, don't forget to install the qwt libraries
or set the LD_LIBRARY_PATH to the lib directory of your local build.

qwt doesn't distribute binary unix packages. qwt.spec is a template
spec file for building rpm packages. Read the comments at the beginning
of qwt.pro how to use it.

一般说来,只要LD_LIBRARY_PATH路径设得对,就没问题

在FC4下 Qt 3.3在 /usr/lib/qt-3.3/ 目录中
为了方便,可以在$QTDIR/bin中建立一个bash文件,起动designer

#!/bin/bash
export QTDIR=/usr/lib/qt-3.3
export LD_LIBRARY_PATH=$(QTDIR)/lib:$(QTDIR)/plugins/designer:/Software/temp/qwt-4.2.0/lib

./designer &

source 它就可以了

You've got to find what you love. -----steve jobs

我再说一次,你不能预先把点点滴滴串在一起;唯有未来回顾时,你才会明白那些点点滴
滴是如何串在一起的。所以你得相信,你现在所体会的东西,将来多少会连接在一块。你
得信任某个东西,直觉也好,命运也好,生命也好,或者业力。这种作法从来没让我失望
,也让我的人生整个不同起来。


有时候,人生会用砖头打你后脑。不要丧失信心。我确信
,我爱我所做的事情,这就是这些年来让我继续走下去的唯一理由。你得找出你爱的,工
作上是如此,对情人也是如此。你的工作将填满你的一大块人生,唯一获得真正满足的方
法就是做你相信是伟大的工作,而唯一做伟大工作的方法是爱你所做的事。如果你还没找
到这些事,继续找,别停顿。尽你全心全力,你知道你一定会找到。而且,如同任何伟大
的关系,事情只会随著时间愈来愈好。所以,在你找到之前,继续找,别停顿。


没有人想死。即使那些想上天堂的人,也想活著上天堂。但是死亡是我们共有的目的地,
没有人逃得过。这是注定的,因为死亡简直就是生命中最棒的发明,是生命变化的媒介,
送走老人们,给新生代留下空间。现在你们是新生代,但是不久的将来,你们也会逐渐变
老,被送出人生的舞台。抱歉讲得这么戏剧化,但是这是真的。
你们的时间有限,所以不要浪费时间活在别人的生活里。不要被信条所惑-盲从信条就是
活在别人思考结果里。不要让别人的意见淹没了你内在的心声。最重要的,拥有跟随内心
与直觉的勇气,你的内心与直觉多少已经知道你真正想要成为什么样的人。任何其他事物
都是次要的。


求知若饥,虚心若愚。

Some icons I made today

Generated by photoshop CS





Using Fireworks to produce Macstyle buttons

苹果的导航(下图)总体的感觉是清淡的色彩配上透明的效果。其实这种效果在fireworks(看多了在PS里的长篇大论)里简简单单,远没有想象的那么复杂。用的技术也是最简单的:渐变填充,层的透明度调节,简单效果(effect)。我们就是要用最简单的技术做出最好的效果 。好的,开始做了,注意听讲。


 1.首先画一个圆角矩形,用渐变填充,效果如图:



2.做出导航按钮的高光,这是点睛之笔,一般在这一步效果就出来了。有两种方实现:一个用效果(effect)的内阴影(Inner Shadow)参数和最终效果如图:



3.另一个是做一个高光的shape,将这个shape的层透明度调成30,参数和最终效果如图:



大体的原理弄懂了,我们再看看其他的按钮就觉得很好做了。换换颜色,形状可以做出太多的效果,正所谓一通百通了。下面是一些例子:



poser

A pic generated by poser 5.0 and photoshop



a startup with 3D figure design

巴列特定律

巴列特定律(也称80/20原理):总结果的80%是由总消耗时间中的20%所形成的
   按事情的“重要程度”编排行事优先次序的准则是建立在“重要的少数与琐碎的多数”的原理的基础上。举例说明:
   80%的销售额是源自20%的顾客;
   80%的电话是来自20%的朋友;
   80%的总产量来自20%的产品;
   80%的财富集中在20%的人手中; ……

避免将时间花在琐碎的多数问题上,因为就算你花了80%的时间,你也只能取得20%的成效。
所以,你应该将时间花于重要的少数问题上,因为掌握了这些重要的少数问题,你只需花20%的时间,即可取得80%的成效。
   掌握重点可以让你的工作计划不致偏差。一旦一项工作计划成为危机时,犯错的几率就会增加。
我们很容易陷在日常琐碎的事情处理中;但是有效进行时间管理的人,总是确保最关键的20%的活动具有最高的优先级。

one of my demos

The preface demo of the contest
it may be revised after the application was finished


The main page



The sensor status page


and The video playback page


hope you enjoy it ....
February 2012
S M T W T F S
January 2012March 2012
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29