锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲黄色免费电影,久久久久久一区二区,99视频国产精品免费观看http://m.shnenglu.com/izualzhy/category/15717.html鍧氭寔 鐩鎬俊鑷繁zh-cnWed, 30 Nov 2011 18:00:23 GMTWed, 30 Nov 2011 18:00:23 GMT6024鐐規父鎴?c++,Qt)http://m.shnenglu.com/izualzhy/archive/2011/11/29/161187.htmlizualzhyizualzhyTue, 29 Nov 2011 12:31:00 GMThttp://m.shnenglu.com/izualzhy/archive/2011/11/29/161187.htmlhttp://m.shnenglu.com/izualzhy/comments/161187.htmlhttp://m.shnenglu.com/izualzhy/archive/2011/11/29/161187.html#Feedback3http://m.shnenglu.com/izualzhy/comments/commentRss/161187.htmlhttp://m.shnenglu.com/izualzhy/services/trackbacks/161187.html璇曠潃鑷繁鍐欎簡涓?4鐐規父鎴忥紝濡傛湁鏀硅繘鎴栬呬笉瀵圭殑鍦版柟璇鋒寚鍑恒?

鍩烘湰鐭ヨ瘑錛?

娓告垙瑙勫垯寰堢畝鍗曪紝灝辨槸鍒╃敤鍔犲噺涔橀櫎灝嗘墤鍏嬬墝鐨勪換涓4寮犵墝鐨勭粍鍚堬紝榪愮畻鍚庡緱鍒扮粨鏋?4.

鐣岄潰鐢≦t瀹屾垚鍚?

clip_image002

clip_image004

鐣岄潰娌℃湁澶氫笅鍔熷か錛屽彲浠ユ坊鍔犳椂闂存彁閱掞紝淇敼鐩爣鏁板鹼紙24錛夛紝澧炲姞鐗屾暟搴旇涔熸槸鍙互鐨勶紝涓嶈繃鎴戞病鏈夊幓璇曚竴涓嬨傛劅瑙夎姳鍝ㄤ簡娌℃湁綆鍗曟潵鐨勫ソ涓浜涖?

next浼氱敓鎴愭柊鐨勭墝銆俛nswer鏌ョ湅絳旀銆?

鐗岀殑鏁板間嬌鐢≦lineEdit鍋氱殑錛屽彲浠ヨ嚜宸辮緗箋?

CardCalculation綾諱細鏍規嵁杈撳叆鐨勭墝鏁?vector<double>)璁$畻鍑哄搷搴旂殑琛ㄨ揪寮忋?

璁$畻嫻佺▼錛?

鏁版嵁緇撴瀯鐨勪功榪樻病鐪嬪畬錛岀畻娉曞畬鍏ㄦ槸鑷繁鍑┖鍘昏瘯銆傛渶鍚庡啓鍑烘潵鍚庡叾瀹炰篃涓嶇煡閬撹嚜宸卞啀鑰冭檻榪欐柟渚塊棶棰樻椂鎬濊礬鎬庝箞灞曞紑銆傚敖蹇娊鏃墮棿鐪嬩笅綆楁硶鐨勪功鎵嶈銆?

鎴戜滑鎷?#8251;浣滀負浠繪剰鐨勬搷浣滅錛?-*/錛夋潵璇存槑銆?

鏍規嵁vec鍏冪礌涓暟:

1. a※b錛岀洿鎺ヨ綆楀嵆鍙?

2. a※b※c,鍙兘鎿嶄綔涓?

(a※b)※c

a※(b※c)

3. a※b※c ※d,鍙兘鎿嶄綔涓猴細

(a※b)※c ※d

a※(b※c) ※d

a※b※(c ※d)

鍥犳閲囩敤閫掑綊姹傝В錛屽ソ澶勬槸濡傛灉澧炲姞鐗岀殑寮犳暟鏃跺簲璇ュ鏄撲慨鏀逛竴浜涳紝鍏蜂綋瀹炵幇鍑芥暟涓篶alCards銆?

鍒氫紶榪泇ec鏃訛紝澶у皬涓?錛屽睘浜庣涓夌鎯呭喌銆傞亶鍘唙ec錛屽皢鍙兘鎿嶄綔鍚庡艦鎴愮殑鏂扮殑vector鍐嶆浣滀負鍑芥暟鍙傛暟浼犲叆錛岀洿鍒伴亣鍒?鎯呭喌榪斿洖錛屽鏋滄弧瓚寵繑鍥瀟rue錛屽惁鍒欒繑鍥瀎alse銆傝繑鍥瀟rue鏃訛紝淇敼絎簩涓弬鏁頒繚瀛樿〃杈懼紡銆?

鍏充簬濡備綍榪斿洖琛ㄨ揪寮忚繖閲屾垜寮勪簡寰堥暱鏃墮棿銆傝綆楀嚭姝g‘鐨勮〃杈懼紡鍚庯紝姣忔閫掑綊閮戒細鍔犱竴瀵規嫭鍙鳳紝鍏跺疄鍚庨潰搴旇鍙互瀵硅〃杈懼紡浼樺寲涓嬪彲鑳藉噺灝戞嫭鍙風殑鏁伴噺錛屼笉榪囨垜娌℃湁鍐欍?

紼嬪簭閲岄兘鍐欎簡娉ㄩ噴~濡傛灉榪樻槸鏈夐棶棰樿緇欐垜鐣欒█J /Files/izualzhy/TwentyFourGame.rar



izualzhy 2011-11-29 20:31 鍙戣〃璇勮
]]>
[杞琞 Qt緇忓吀鍑洪敊淇℃伅涔媢ndefined reference to `vtable for classnamehttp://m.shnenglu.com/izualzhy/archive/2011/10/28/159246.htmlizualzhyizualzhyThu, 27 Oct 2011 16:16:00 GMThttp://m.shnenglu.com/izualzhy/archive/2011/10/28/159246.htmlhttp://m.shnenglu.com/izualzhy/comments/159246.htmlhttp://m.shnenglu.com/izualzhy/archive/2011/10/28/159246.html#Feedback0http://m.shnenglu.com/izualzhy/comments/commentRss/159246.htmlhttp://m.shnenglu.com/izualzhy/services/trackbacks/159246.html鏈珯鎵鏈夋枃绔犵敱鏈珯鍜屽師浣滆呬繚鐣欎竴鍒囨潈鍔涳紝浠呭湪淇濈暀鏈増鏉冧俊鎭佸師鏂囬摼鎺ャ佸師鏂囦綔鑰呯殑鎯呭喌涓嬪厑璁歌漿杞斤紝杞澆璇峰嬁鍒犳敼鍘熸枃鍐呭錛?騫朵笉寰楃敤浜庡晢涓氱敤閫斻?璋㈣阿鍚堜綔銆?

鍘熸枃閾炬帴:Qt緇忓吀鍑洪敊淇℃伅涔媢ndefined reference to `vtable for classname

榪欎釜鍑洪敊淇℃伅澶父瑙佷簡錛岀敤榪嘠t涓や釜鏈堜互涓婄殑鏈嬪弸鍩烘湰涓婇兘鑳借嚜宸辮В鍐充簡錛屽洜涓哄お緇忓吀浜嗭紝鍙互緇欐柊鎵嬪弬鑰冦?

鍑洪敊淇℃伅涓鑸被浼?undefined reference to `vtable for classname MyWidget`
鍦ㄦ墽琛宮ake鍛戒護鍚庡嚭鐜般?

鍑洪敊鍘熷洜鏄湪瀹氫箟綾葷殑鏃跺欎負浜嗚兘浣跨敤signals鍜宻lot,鍦ㄧ被瀹氫箟鐨勫悗闈㈠姞浜哘_OBJECT寮曡搗銆?鍥犱負Q_OBJECT鏄竴涓畯錛屽湪涓嶅悓鐨勭被涓睍寮鏄笉鍚岀殑浠g爜錛屼緥濡傚湪mywidgeth.h涓敓鎴愮殑

public:

template inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const {

int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i;

}

static const QMetaObject staticMetaObject;

virtual const QMetaObject *metaObject() const;

virtual void *qt_metacast(const char *);

static inline QString tr(const char *s, const char *c = 0) {

return staticMetaObject.tr(s, c);

}

static inline QString trUtf8(const char *s, const char *c = 0)

{

return staticMetaObject.trUtf8(s, c);

}

static inline QString tr(const char *s, const char *c, int n) {

return staticMetaObject.tr(s, c, n);

}

static inline QString trUtf8(const char *s, const char *c, int n) {

return staticMetaObject.trUtf8(s, c, n);

}

virtual int qt_metacall(QMetaObject::Call, int, void **); private:

鍙互鐪嬪埌浠ヤ笂鐨勪唬鐮佸0鏄庝簡3涓粠鐖剁被緇ф壙鐨?涓櫄鍑芥暟銆傛湰鏉ヨ繖涓変釜鍑芥暟鐨勫疄鐜板簲璇ユ槸鐢眒oc_mywidget.cpp鏉ュ畬鎴愩?br/>鑰屽綋鍓嶇殑閿欒姝f槸鍥犱負Makefile閲屾病鏈夊皢moc_mywidget.cpp鍔犲叆緙栬瘧寮曡搗銆?

Makefile鑳屽悗鐨勫師鍥犳槸qmake錛屽洜涓篞t鐨勭紪璇戠郴緇熸槸閫氳繃qmake灝?pro鏂囦歡杞崲鎴怣akefile鏂囦歡銆傚綋qmake鎵弿.h浠g爜鏃跺彂鐜版湁Q_OBJECT榪欐牱瀛楃溂鐨勪唬鐮佹椂錛屼細灝嗕竴涓敤moc鐢熸垚moc_xxx.cpp浠g爜鐨勪緷璧栧叧緋誨啓鍒癕akefile閲屻傚鏋滄壂鎻忔椂娌℃湁鎵懼埌Q_OBJECT灝變笉浼氱敓鎴愰澶栫殑moc_xxx.cpp榪欐牱鐨勬枃浠躲?

鍑虹幇鏈鍒濅竴騫曠殑鍘熷洜鏄湪鎵цqmake鐨勬椂鍊?h浠g爜閲屽茍娌℃湁O_OBJECT榪欐牱鐨勪唬鐮併傝屾墽琛宮ake鐨勬椂鍊?h閲屽凡緇忔湁Q_OBJECT浜嗭紝瑙e喅鐨勬柟娉曞氨鏄噸鏂版墽琛宷make錛岀劧鍚庢墽琛宮ake.

鈥斺?

shiroki錛氬彟澶栨垜鍐嶅姞涓鍙ワ紝 榪樻湁涓縐嶅彲鑳芥ф槸鍐欎唬鐮佺殑浜烘妸鎵鏈夌殑浠g爜閮藉啓鍦ㄤ簡.cpp鏂囦歡涓傝鐭ラ亾moc宸ュ叿鍙.h鏂囦歡錛屽鏋滄妸Q_OBJECT瀹忔斁鍦╟pp閲宮oc鏄湅涓嶅埌鐨勨︹︽墍浠ュぇ瀹跺啓浠g爜榪樻槸瑕侀伒瀹堝0鏄庢斁.h瀹炵幇鏀綾pp鐨勮鐭╂瘮杈冨ソ銆?



izualzhy 2011-10-28 00:16 鍙戣〃璇勮
]]>
QtExample_QXmlStreamWriter Bookmarkshttp://m.shnenglu.com/izualzhy/archive/2011/06/19/148970.htmlizualzhyizualzhySun, 19 Jun 2011 09:13:00 GMThttp://m.shnenglu.com/izualzhy/archive/2011/06/19/148970.htmlhttp://m.shnenglu.com/izualzhy/comments/148970.htmlhttp://m.shnenglu.com/izualzhy/archive/2011/06/19/148970.html#Feedback0http://m.shnenglu.com/izualzhy/comments/commentRss/148970.htmlhttp://m.shnenglu.com/izualzhy/services/trackbacks/148970.html


紼嬪簭榪愯鏁堟灉鍥?br />
璐熻矗澶勭悊xml鏂囦歡鐨勬槸XbelWriter錛孹belReader錛岀晫闈㈢殑瀹炵幇鏄敱MainWindow瀹屾垚鐨?/p>

淇濆瓨鍚庣殑xbel鏂囦歡鍓嶅嚑琛屾槸榪欐牱鐨?br /><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xbel>
<xbel version="1.0">
    <folder folded="yes">
        <title>Literate Programming</title>
        <bookmark href="            <title>Synopsis of Literate Programming</title>
        </bookmark>
濡傛灉涓嶆柇鐢╮eadNext錛堬級錛屽嵆浠ヤ笅鍑犺浠g爜璇誨彇鏂囦歡鐨勮瘽
    while (!xml.atEnd()) {
        qDebug() << "name " << xml.name() << "tokentype " << xml.tokenType();
        if (xml.isCharacters()) {
            qDebug() << xml.text();
        }
        xml.readNext();
    }
鍓嶅嚑琛岃緭鍑猴細
name  "" tokentype  0
name  "" tokentype  2
name  "" tokentype  8
name  "xbel" tokentype  4
name  "" tokentype  6
"
    "
name  "folder" tokentype  4
name  "" tokentype  6
"
        "
name  "title" tokentype  4
name  "" tokentype  6
"Literate Programming"
name  "title" tokentype  5
name  "" tokentype  6
"
        "
name  "bookmark" tokentype  4
name  "" tokentype  6
"
            "
name  "title" tokentype  4
name  "" tokentype  6
"Synopsis of Literate Programming"
name  "title" tokentype  5
緇撳悎婧愪唬鐮侀噷鍏充簬Tokentype鐨別num瀹氫箟錛?br />enum TokenType {
        NoToken = 0,
        Invalid,
        StartDocument,
        EndDocument,
        StartElement,
        EndElement,
        Characters,
        Comment,
        DTD,
        EntityReference,
        ProcessingInstruction
    };
鍙互鐪嬪嚭錛?br />1.readNext灝辨槸涓涓竴涓殑鏉ヨ錛岀鍒?lt;xxx>,</xxx>,浠ュ強...>xxx<...鐨勬枃瀛?br /> 鐞嗕竴涓嬭鍙栫殑嫻佺▼錛?br />  1.娌℃湁璇誨彇浠諱綍涓滆タ錛孨oToken
  2.璇誨彇<?xml version="1.0" encoding="UTF-8"?>錛孲tartDocument
  3.璇誨彇<!DOCTYPE xbel>錛孌TD
  4.璇誨彇<xbel version="1.0">錛孲tartElement
  5.璇誨彇<xbel version="1.0">涓?lt;folder folded="yes">涔嬮棿鐨刢haracters錛屽鏋滄墦鍗扮浉搴旂殑unicode鍑烘潵鐨勮瘽錛屾槸10 32 32 32 32
 鍗?涓崲琛?4涓┖鏍鹼紝鐩存帴鎵撳嵃灝辨槸
"
    "
榪欎釜浜嗭紝鍙...>xxx<...鐨勬枃瀛楅兘浼氳鍙栵紝鍗充嬌鏄崲琛?絀烘牸涔嬬被鐨?br />  6.璇誨彇<folder folded="yes">錛孲tartElement
  銆傘傘傘傘傘?br />2.
閬囧埌榪欑<separator/>鍒欑被浼間簬<separator></separator>
name  "separator" type  4
name  "separator" type  5
鍒╃敤void QXmlStreamWriter::writeEmptyElement("separator")鍙互鍐欏叆鎴愯繖鏍?/p>

1.XbelWriter Class
鍐欏叆鐨勮繃紼嬪叾瀹炴槸寰堢畝鍗曠殑錛屽叿浣撶湅浠g爜錛?br /> bool XbelWriter::writeFile(QIODevice *device)
 {
     xml.setDevice(device);

     xml.writeStartDocument();//鐢熸垚L1
     xml.writeDTD("<!DOCTYPE xbel>");//鐢熸垚L2
     xml.writeStartElement("xbel");//涓庝笅涓琛屽叡鍚岀敓鎴怢3
     xml.writeAttribute("version", "1.0");
     for (int i = 0; i < treeWidget->topLevelItemCount(); ++i)
         writeItem(treeWidget->topLevelItem(i));

     xml.writeEndDocument();
     return true;
 }
2.XbelReader Class
棣栧厛璇誨彇鍒板悎閫傜殑Element
 bool XbelReader::read(QIODevice *device)
 {
     xml.setDevice(device);

     if (xml.readNextStartElement()) {
         if (xml.name() == "xbel" && xml.attributes().value("version") == "1.0")//鍗寵鍒皀ame涓簒bel錛屽睘鎬ersion涓?.0鐨凟lement鏃?br />//The actual process of reading only takes place if the file is a valid XBEL 1.0 file.
             readXBEL();
         else
             xml.raiseError(QObject::tr("The file is not an XBEL version 1.0 file."));
     }

     return !xml.error();
 }
鐢辨敞閲婂彲浠ョ湅鍒板伐浣滃嚱鏁版槸readXBEL(),鏁翠釜嫻佺▼鐢辮繖鍑犺浠g爜瀹屾垚錛堥噷闈㈠嚱鏁扮敤鍒伴掑綊錛?br />void XbelReader::readXBEL()
 {
     Q_ASSERT(xml.isStartElement() && xml.name() == "xbel");

     while (xml.readNextStartElement()) {
         if (xml.name() == "folder")
             readFolder(0);
         else if (xml.name() == "bookmark")
             readBookmark(0);
         else if (xml.name() == "separator")
             readSeparator(0);
         else
             xml.skipCurrentElement();
     }
 }
鐪嬩笅skipCurrentElement()鐨勬簮浠g爜錛?br />void QXmlStreamReader::skipCurrentElement()
{
    int depth = 1;
    while (depth && readNext() != Invalid) {
        if (isEndElement())
            --depth;
        else if (isStartElement())
            ++depth;
    }
}錛屽彲浠ョ湅鍒板彉閲廳epth鍦ㄨ繘鍏ヤ竴涓柊鐨別lement鍒?1錛屽嚭鏉ュ垯-1
鍥犳鐩村埌鐜板湪鐨勮繖涓猠lement緇撴潫錛堥亣鍒扮浉搴旂殑</xxx>錛夛紝鍑芥暟鎵嶇粨鏉熼鍑?br />Qt Assistant閲岀殑娉ㄩ噴錛?br />The readXBEL() function reads the name of a startElement and calls the appropriate function to read it, depending on whether if its a "folder", "bookmark" or "separator". Otherwise, it calls skipCurrentElement().
鍗沖鏋淓lement鐨刵ame涓篺older,bookmark,separator鏃訛紝璇誨叆鍐呭錛屽惁鍒檚kip
鍏蜂綋浼氶亣鍒扮殑鏈夎繖涔堝嚑縐嶏細
<folder folded="yes">
<title>Literate Programming</title>
<bookmark href="
<separator/>
闇瑕佷笉鍚岀殑鍑芥暟鏉ュ鐞?br />渚嬪瓙閲屽垎鍒敤浜?br />readTitle(),readSeparator(),readFolder(),readBookmark()

鎴戜富瑕佸涔犱簡涓媟eadFolder()
fold鏈変袱縐嶆儏鍐?br /><folder folded="yes">
<folder folded="no">
璇誨彇鏃跺樊鍒殑澶勭悊浠g爜
    QTreeWidgetItem *folder = createChildItem(item);
    bool folded = (xml.attributes().value("folded") != "no");
    treeWidget->setItemExpanded(folder, !folded);
絎笁琛屾敞閲婃帀鍚庡姣斾笅鍥劇墖

鍙榛樿鏄笉expand鐨?br />Sets the item referred to by item to either closed or opened, depending on the value of expand.

This function is deprecated. Use QTreeWidgetItem::setExpanded() instead.
void QTreeWidgetItem::setExpanded ( bool expand )
Expands the item if expand is true, otherwise collapses the item
涓昏鏄睍寮榪樻槸鎽哄彔欏廣?br />folder涓嬮潰鐨別lement鍙兘name涓簍itle錛宐ookmark錛宻eparator錛岃繕鍙兘鍐嶇敱folder錛屽儚Useful C++ Links涓嬮潰榪樻湁STL Qt絳夛紝闇瑕侀掑綊澶勭悊錛屽洜姝よ繕闇瑕佷互涓嬩唬鐮?br />    while (xml.readNextStartElement()) {
        if (xml.name() == "title")
            readTitle(folder);
        else if (xml.name() == "folder")
            readFolder(folder);
        else if (xml.name() == "bookmark")
            readBookmark(folder);
        else if (xml.name() == "separator")
            readSeparator(folder);
        else
            xml.skipCurrentElement();
    }
鍙笉榪囪窡readXBEL閲屽弬鏁頒笉鍚?/p>

鍐嶇湅涓媤hile-loop condition
bool QXmlStreamReader::readNextStartElement ()
Reads until the next start element within the current element. Returns true when a start element was reached. When the end element was reached, or when an error occurred, false is returned.

The current element is the element matching the most recently parsed start element of which a matching end element has not yet been reached. When the parser has reached the end element, the current element becomes the parent element.

This is a convenience function for when you're only concerned with parsing XML elements.
鐪嬩笅璇ュ嚱鏁版簮浠g爜錛?br />bool QXmlStreamReader::readNextStartElement()
{
    while (readNext() != Invalid) {
        if (isEndElement())
            return false;
        else if (isStartElement())
            return true;
    }
    return false;
}
鍙互鐪嬪埌鏄鍙栦笅涓涓鍙鳳紝濡傛灉鏄痚ndElement錛屽垯榪斿洖false錛屽惁鍒檛rue
鍐嶅姣斾笅xml鏂囦歡鐪嬩笅璇ュ嚱鏁版槸濡備綍鐢ㄦ潵鍦ㄨ繖涓ぇ鐨別lement鍐呴儴閬嶅巻鐨?br /><folder folded="yes">
        <title>Literate Programming</title>
        <bookmark href="
            <title>Synopsis of Literate Programming</title>
        </bookmark>
        <bookmark href="
            <title>Literate Programming: Propaganda and Tools</title>
        </bookmark>
1.璇誨埌璁板彿涓?lt;title>錛岃繘鍏eadTitle()
2.璇誨彇鍐呭錛岃鍙風Щ鍔ㄥ埌</title>
3.榪涘叆while鏉′歡錛屽嵆readNextStartElement()錛屾鏃惰櫧鐒禩okenType鏄疎ndElement錛屼絾鏄痳eadNext鍚庯紝鍙樹負startElement錛屽嵆bookmark錛岃繘鍏eadBookmark()
4.鍚宖older錛宐ookmark涔熶竴鐩磋璇誨埌</bookmark>

鍐嶇湅涓?br />QTreeWidgetItem *XbelReader::createChildItem(QTreeWidgetItem *item)
{
    QTreeWidgetItem *childItem;
    if (item) {
        childItem = new QTreeWidgetItem(item);
    } else {
        childItem = new QTreeWidgetItem(treeWidget);
    }
    childItem->setData(0, Qt::UserRole, xml.name().toString());
    return childItem;
}
setData鍙傛暟鍙互鎸囧畾涓嶅悓鐨剅ole
Qt::UserRole 32 The first role that can be used for application-specific purposes.
閫氳繃鐩稿簲鐨刣ata鍑芥暟鍙互鍙栧嚭璇String
閫氳繃緇?br />QTreeWidgetItem鐨勬瀯閫犲嚱鏁頒紶鍏ヤ笉鍚岀殑鍙傛暟錛屽彲浠ヤ紶鍏TreeWidget錛屼篃鍙互鏄疩TreeWidgetItem
QTreeWidget浼氭牴鎹悇涓猧tem鐨勫叧緋昏屾帓鍒楀ソ緙╄繘錛熷叧浜嶲TreeWidget榪樻病鐢ㄨ繃錛屾湁絀鴻瀛︿範涓涓嬨?br />



izualzhy 2011-06-19 17:13 鍙戣〃璇勮
]]>
QtExample______DomBookmarkshttp://m.shnenglu.com/izualzhy/archive/2011/06/19/148969.htmlizualzhyizualzhySun, 19 Jun 2011 09:09:00 GMThttp://m.shnenglu.com/izualzhy/archive/2011/06/19/148969.htmlhttp://m.shnenglu.com/izualzhy/comments/148969.htmlhttp://m.shnenglu.com/izualzhy/archive/2011/06/19/148969.html#Feedback0http://m.shnenglu.com/izualzhy/comments/commentRss/148969.htmlhttp://m.shnenglu.com/izualzhy/services/trackbacks/148969.html鍏堢湅涓嬬▼搴忚繍琛岀殑緇撴灉鍥?img border="0" alt="" src="http://m.shnenglu.com/images/cppblog_com/izualzhy/DomBookmarks.png" width="478" height="349" />

璺熶嬌鐢≦XmlStreamReader QXmlStreamWriter鏄竴鏍風殑錛屽尯鍒湪浜庡鐞嗙殑榪囩▼銆?br />鍓嶄竴涓緥瀛愪富瑕佹槸浼犲弬鐨勬柟寮忥紝灝哘TreeWidget浼犵粰xmlReader錛寈mlWriter
璇誨彇xml鍒癚TreeWidget閲岋紝闅忕潃璇誨叆娣誨姞item鍒伴噷闈紝鍐欑殑鏃跺欏垯閬嶅巻榪欎釜QTreeWidget錛屾妸item鍐欏叆鍒皒ml鏂囦歡
榪欎釜渚嬪瓙鍒欐槸鐢盦TreeWidget媧劇敓涓涓猉belTree鐨勭被鍑烘潵錛岀鏈夋垚鍛橀噷鏈変竴涓猀DomDocument鐨勫璞°?br />綆楁槸涓ょ澶勭悊鏂瑰紡鍚э紝浣嗕紶鍙傚拰緇勫悎鐨勬柟寮忔瘡涓緥瀛愰兘鏄彲浠ョ敤鐨勶紝鍙兘鍙槸QXmlStream鍜孮Dom鏇撮傚悎鍝鏂瑰紡閲屼簡銆?br />榪欎釜渚嬪瓙涓昏鏄涔燪Dom Classes

鍏堣創涓涓猀t Assistant閲岀殑涓孌典唬鐮?br />The QDom classes are typically used as follows:

 QDomDocument doc("mydocument");
 QFile file("mydocument.xml");
 if (!file.open(QIODevice::ReadOnly))
     return;
 if (!doc.setContent(&file)) {
     file.close();
     return;
 }
 file.close();

 // print out the element names of all elements that are direct children
 // of the outermost element.
 QDomElement docElem = doc.documentElement();

 QDomNode n = docElem.firstChild();
 while(!n.isNull()) {
     QDomElement e = n.toElement(); // try to convert the node to an element.
     if(!e.isNull()) {
         cout << qPrintable(e.tagName()) << endl; // the node really is an element.
     }
     n = n.nextSibling();
 }

 // Here we append a new element to the end of the document
 QDomElement elem = doc.createElement("img");
 elem.setAttribute("src", "myimage.png");
 docElem.appendChild(elem);

Once doc and elem go out of scope, the whole internal tree representing the XML document is deleted.

To create a document using DOM use code like this:

 QDomDocument doc("MyML");
 QDomElement root = doc.createElement("MyML");
 doc.appendChild(root);

 QDomElement tag = doc.createElement("Greeting");
 root.appendChild(tag);

 QDomText t = doc.createTextNode("Hello World");
 tag.appendChild(t);

 QString xml = doc.toString();

鍔犱笂榪欏嚑鍙ヨ瘽浜х敓xml鏂囦歡鏌ョ湅鍐呭
    QFile file("mydocument.xml");
    file.open(QIODevice::ReadWrite);

    QTextStream m_out(&file);

    doc.save(m_out,4);
    file.close();
浜х敓鐨刣ocument鍐呭錛?br /><!DOCTYPE MyML>
<MyML>
    <Greeting>Hello Wolrd!</Greeting>
</MyML>

1.
XbelTree緇ф壙鑷猀TreeWidget
姣忎竴鍒楃殑澶у皬鏄惁鍙互鑷敱鏀瑰彉錛岀敱璇ュ嚱鏁板喅瀹?br />void QHeaderView::setResizeMode ( ResizeMode mode )
Sets the constraints on how the header can be resized to those described by the given mode.
The resize mode specifies the behavior of the header sections. It can be set on the entire header view or on individual sections using setResizeMode().


Constant Value Description
QHeaderView::Interactive 0 The user can resize the section. The section can also be resized programmatically using resizeSection(). The section size defaults to defaultSectionSize. (See also cascadingSectionResizes.)
QHeaderView::Fixed 2 The user cannot resize the section. The section can only be resized programmatically using resizeSection(). The section size defaults to defaultSectionSize.
QHeaderView::Stretch 1 QHeaderView will automatically resize the section to fill the available space. The size cannot be changed by the user or programmatically.
QHeaderView::ResizeToContents 3 QHeaderView will automatically resize the section to its optimal size based on the contents of the entire column or row. The size cannot be changed by the user or programmatically. (This value was introduced in 4.2)

鏈涓婁竴鎺掔殑headview鐨勬寚閽堥氳繃璇ュ嚱鏁拌幏寰?br />QHeaderView * QTreeView::header () const
Returns the header for the tree view.
2.
<img src="myimg.png">
tagName:img
name:src
value:"myimg.png"

QDom
A
QDomElement QDomDocument::documentElement () const
Returns the root element of the document.
璇ュ嚱鏁拌繑鍥炵殑鍗沖湪DOCTYPE鍚庢渶澶х殑涓涓狤lement錛屽嵆root
B
QDomElement QDomNode::firstChildElement ( const QString & tagName = QString() ) const
Returns the first child element with tag name tagName if tagName is non-empty; otherwise returns the first child element. Returns a null element if no such child exists.
璇ュ嚱鏁拌繑鍥炴寚瀹歵agName鐨凲DomElement
鐩稿叧鐨勬湁
firstChildElement(),lastChildElement(), previousSiblingElement(), and nextSiblingElement().
閮介渶瑕佹寚瀹歵agName
褰撳瓙緇撶偣鐨勪笉鏄竴涓狤lement鏃訛紝浣跨敤鍑芥暟鑾峰緱絎竴涓瓙鑺傜偣
QDomNode QDomNode::firstChild () const
Returns the first child of the node. If there is no child node, a null node is returned. Changing the returned node will also change the node in the document tree.
鑾峰緱鏈鍚庝竴涓瓙緇撶偣
QDomNode QDomNode::lastChild () const
Returns the last child of the node. If there is no child node, a null node is returned. Changing the returned node will also change the node in the document tree.

See also firstChild() and childNodes().
鑾峰緱涓嬩竴涓瓙鑺傜偣
QDomNode QDomNode::nextSibling () const
Returns the next sibling in the document tree. Changing the returned node will also change the node in the document tree.

If you have XML like this:

 <h1>Heading</h1>
 <p>The text...</p>
 <h2>Next heading</h2>
and this QDomNode represents the <p> tag, nextSibling() will return the node representing the <h2> tag.

鑾峰緱涓婁竴涓瓙鑺傜偣
QDomNode QDomNode::previousSibling () const
Returns the previous sibling in the document tree. Changing the returned node will also change the node in the document tree.

For example, if you have XML like this:

 <h1>Heading</h1>
 <p>The text...</p>
 <h2>Next heading</h2>
and this QDomNode represents the &lt;p&gt; tag, previousSibling() will return the node representing the &lt;h1&gt; tag.
浣犱篃鍙互鐩存帴鑾峰緱緇撶偣鐨勫垪琛?br />QDomNodeList QDomNode::childNodes () const
Returns a list of all direct child nodes.

Most often you will call this function on a QDomElement object.

For example, if the XML document looks like this:

 <body>
 <h1>Heading</h1>
 <p>Hello <b>you</b></p>
 </body>
Then the list of child nodes for the "body"-element will contain the node created by the &lt;h1&gt; tag and the node created by the &lt;p&gt; tag.

The nodes in the list are not copied; so changing the nodes in the list will also change the children of this node.


 



izualzhy 2011-06-19 17:09 鍙戣〃璇勮
]]>
杞?Qt閫氳繃dom鏂瑰紡淇敼xml http://m.shnenglu.com/izualzhy/archive/2011/06/09/148379.htmlizualzhyizualzhyThu, 09 Jun 2011 15:21:00 GMThttp://m.shnenglu.com/izualzhy/archive/2011/06/09/148379.htmlhttp://m.shnenglu.com/izualzhy/comments/148379.htmlhttp://m.shnenglu.com/izualzhy/archive/2011/06/09/148379.html#Feedback0http://m.shnenglu.com/izualzhy/comments/commentRss/148379.htmlhttp://m.shnenglu.com/izualzhy/services/trackbacks/148379.html

DOM鏄竴縐嶈В鏋愮敱涓囩淮緗戝崗浼?W3C)鎵寮鍙戠殑XML鏂囨。鐨勬爣鍑嗗簲鐢ㄧ▼搴忕紪紼嬫帴鍙c俀t鎻愪緵涓濂楃敤浜庤鍙栥佹搷浣滃拰緙栧啓XML鏂囨。鐨勯潪楠岃瘉鍨嬩簩綰OM瀹炵幇銆?/p>

DOM鎶奨ML鏂囦歡琛ㄧず鎴愬唴瀛樹腑鐨勪竴媯墊爲銆傛垜浠彲浠ユ寜闇瑕侀亶鍘嗚繖涓狣OM鏍戯紝涔熷彲浠ヤ慨鏀硅繖涓爲騫舵妸瀹冧綔涓篨ML鏂囦歡淇濆瓨鍒扮鐩樹腑銆?/p>

璁╂垜浠冭檻濡備笅榪欎釜XML鏂囨。錛?/p>

<doc>

         <quote>Scio me nihil scire</quote>

         <translation>I know that I know nothing></translation>

</doc>

瀹冨浜庡涓嬫墍紺虹殑DOM鏍戯細

Document

       Element(doc)

              Element(quote)

                     Text(“Scio me nihil scire”)

              Element(translation)

                     Text(“I know that I know nothing”)

榪欎釜DOM鏍戝寘鍚笉鍚岀被鍨嬬殑鑺傜偣銆備緥濡傦紝Element鑺傜偣瀵瑰簲鎵撳紑鏍囩浠ュ強涓庡畠鍖歸厤鐨勫叧闂爣絳俱?font color="#0000ff">鍦ㄨ繖涓や釜鏍囩涔嬮棿鐨勫唴瀹瑰垯浣滀負榪欎釜Element鑺傜偣鐨勫瓙鑺傜偣鍑虹幇銆?/font>錛堟敞鎰忚摑鑹插瓧浣擄級

涓婇潰鐨勪粙緇嶄富瑕佹槸鐢ㄦ潵璇存槑dom鏍戠殑緇撴瀯鎯呭喌錛屼笅闈㈠垯榪涘叆姝i鐪嬪浣曢氳繃qt鏉ヨ揪鍒頒慨鏀箈ml鏂囦歡鐨勭洰鐨勩傛湰鏂囦腑涓昏璇存槑濡備綍淇敼xml灞炴у間互鍙婅妭鐐瑰鹼紝

淇敼灞炴у肩殑浠g爜濡備笅錛?/font>

bool QXmlEdit::SetAValue(const QString &key, const QVariant &value)
{
    try
    {
        QString tag;
        QString attName;
        QStringList sl=key.split("/");
        tag = sl.at(0);
        attName = sl.at(1);

        QDomElement docElem = doc.documentElement();
        QDomNodeList nodeList = docElem.elementsByTagName(tag);
        if (nodeList.count() >0 )
        {
            QDomElement el = nodeList.at(0).toElement();
            el.setAttribute(attName,value.toString());  //璁劇疆灞炴у?/span>
            QFile file(fileName);
            if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
            {
                return false;
            }
            QTextStream out(&file);
            doc.save(out,4);
        }
        return true;
    }
    catch (...)
    {
        return false;
    } 
}
淇敼鑺傜偣鍊肩殑浠g爜濡備笅錛?/font>
bool QXmlEdit::SetTValue(const QString &key, const QVariant &value)
{
    try
    {
        QDomElement docElem = doc.documentElement();
        QDomNodeList nodeList = docElem.elementsByTagName(key);
        if (nodeList.count() >0 )
        {
            QDomElement el = nodeList.at(0).toElement();  //tag涓簁ey鐨勮妭鐐?
            QDomNode oldnode = el.firstChild();           //鏍囩涔嬮棿鐨勫唴瀹逛綔涓鴻妭鐐圭殑瀛愯妭鐐瑰嚭鐜幫紝寰楀埌鍘熸潵鐨勫瓙鑺傜偣
            el.firstChild().setNodeValue(value.toString());   //鐢ㄦ彁渚涚殑value鍊兼潵璁劇疆瀛愯妭鐐圭殑鍐呭
            QDomNode newnode = el.firstChild();               //鍊間慨鏀硅繃鍚庣殑瀛愯妭鐐?/span>
            el.replaceChild(newnode,oldnode);                 //璋冪敤鑺傜偣鐨剅eplaceChild鏂規硶瀹炵幇淇敼鍔熻兘
        
            QFile file(fileName);
            if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
            {
                return false;
            }
            QTextStream out(&file);
            doc.save(out,4);
        }
        return true;
    }
    catch (...)
    {
        return false;
    }
}

鑷蟲鎴戜滑灝卞疄鐜頒簡淇敼xml灞炴у強text鐨勫姛鑳姐?/p>

izualzhy 2011-06-09 23:21 鍙戣〃璇勮
]]>
QtExample___OrderFormhttp://m.shnenglu.com/izualzhy/archive/2011/05/22/146929.htmlizualzhyizualzhySun, 22 May 2011 07:19:00 GMThttp://m.shnenglu.com/izualzhy/archive/2011/05/22/146929.htmlhttp://m.shnenglu.com/izualzhy/comments/146929.htmlhttp://m.shnenglu.com/izualzhy/archive/2011/05/22/146929.html#Feedback0http://m.shnenglu.com/izualzhy/comments/commentRss/146929.htmlhttp://m.shnenglu.com/izualzhy/services/trackbacks/146929.html
Enter Customer Details鏄疧rder Form紿楀彛鐐瑰嚮File-New鍚庣殑緇撴灉
褰揈nter Customer Details鐨凬ame鎴栬匒ddress涓虹┖鏃訛紝浼氬脊鍑篒ncomplete Form鐨凪essageBox
瀛︿範璇ヤ緥瀛愪富瑕佹槸鎯充簡瑙e熀浜嶲TextCursor鐨勬搷浣滄柟娉曪紝鏂囨。甯冨眬
1
QDialogButtonBox鍜孮MessageBox
A
Enter Customer Details紿楀彛鐨勫彸涓婥ancel OkButton灝辨槸鎷縌DialogButtonBox鐢熸垚鐨勶紝涔嬫墍浠ョ敤榪欎釜Qt assitant緇欏嚭鐨勮В閲婃槸
Also, a QCheckBox and a QDialogButtonBox are defined; the former to provide the user with the option to receive information on products and offers, and the latter to ensure that buttons used are arranged according to the user's native platform銆?br />闄や簡榪欑偣澶栵紝鐢ㄨ搗鏉ヤ篃姣斿崟鐙幓瀹氫箟Button鏂逛究錛屼綋鐜板湪榪欓噷
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
                                      | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(verify()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

Ok Cancel Button鍙互鐩存帴浣跨敤錛屽啀鐪嬩笅accepted錛宺ejected淇″彿鍦ㄤ粈涔堟儏鍐典笅鍙戦?br />void QDialogButtonBox::accepted ()   [signal]
This signal is emitted when a button inside the button box is clicked, as long as it was defined with the AcceptRole or YesRole.
void QDialogButtonBox::rejected ()   [signal]
This signal is emitted when a button inside the button box is clicked, as long as it was defined with the RejectRole or NoRole.
錛岃孫k cancel Button鐨勫畾涔夛細
QDialogButtonBox::Ok 0x00000400 An "OK" button defined with the AcceptRole.
銆傘傘?
QDialogButtonBox::Cancel 0x00400000 A "Cancel" button defined with the RejectRole.
姝ゅ榪樻湁寰堝Button錛屽Save Apply絳夛紝閮藉畾涔夊湪
enum QDialogButtonBox::StandardButton
flags QDialogButtonBox::StandardButtons閲屼簡銆?br />鐢ㄨ搗鏉ユ槸涓嶆槸寰堟柟渚垮憿錛?br />涓嶈繃璇ョ被榪樻湁寰堝涓滆タ娌$湅鎳傦紝濡侫ctionRole絳夛紝鎰熻鏈夌┖榪欎釜綾誨彲浠ュ崟鐙涔犱竴涓嬨?br />B
Incomplete Form Widget鏄竴涓猀MEssgeBOx錛氾細warning
涔嬫墍浠ヤ袱涓被褰掔粨涓轟竴涓煡璇嗙偣錛屾槸鍥犱負QMessageBox涓庝笂闈㈢殑綾繪湁涓鐐硅繕鏄緢鍍忕殑錛岄偅灝辨槸Button涓嶇敤瀹氫箟銆傘傘?br />QMessageBox鐨凚utton閮藉畾涔夊湪榪欓噷浜?br />enum QMessageBox::StandardButton
flags QMessageBox::StandardButtons
璺熶笂闈㈢殑寰堝儚
鐢ㄨ搗鏉ヤ篃闈炲父鏂逛究錛岀湅涓婭ncomplete Form Widget鐨勭浉鍏充唬鐮?br />QMessageBox::StandardButton answer;
     answer = QMessageBox::warning(this, tr("Incomplete Form"),
         tr("The form does not contain all the necessary information.\n"
            "Do you want to discard it?"),
         QMessageBox::Yes | QMessageBox::No);

     if (answer == QMessageBox::Yes)
         reject();

鍏充簬warning鐨勫畾涔?br />Static Public Members
銆傘傘?br />StandardButton warning ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )
娉ㄦ剰鏄疭tatic鐨?br />榪斿洖綾誨瀷鍗充負涓婇潰璇寸殑鏋氫婦綾誨瀷
2.
QTableView鐨勪笂杈瑰拰宸﹁竟1 2/1 2 3 4鐨勭獥鍙d篃鍙互榪涗竴姝ユ搷浣?br />閫氳繃
QHeaderView * horizontalHeader () const
鎷垮埌瀵瑰簲鎸囬拡錛屼緥濡?br />itemsTable->verticalHeader()->hide();灝卞彲浠ュ皢宸﹁竟鐨? 2 3 4闅愯棌浜?br />3.
QAction * QMenu::addAction ( const QString & text )
This convenience function creates a new action with text. The function adds the newly created action to the menu's list of actions, and returns it.
榪欎釜鍑芥暟闈炲父濂界敤錛屽洜涓哄彲浠ヨ嚜鍔ㄥ垱寤轟竴涓猘ction錛岃繑鍥炲煎氨鏄繖涓猘ction鐨勬寚閽堬紝鍚屾椂鍙﹀鍑犱釜閲嶈澆鍑芥暟鏈夌殑鏇村姞鏂逛究
QAction * QMenu::addAction ( const QString & text, const QObject * receiver, const char * member, const QKeySequence & shortcut = 0 )
This is an overloaded function.

This convenience function creates a new action with the text text and an optional shortcut shortcut. The action's triggered() signal is connected to the receiver's member slot. The function adds the newly created action to the menu's list of actions and returns it.
鍦ㄥ垱寤虹殑鏃跺欙紝鍙互鐩存帴鎸囧畾榪炴帴鍒扮殑妲姐?br />渚嬪瓙閲岃繖閲屽垎鍒敤鍒頒簡錛?br />QAction *newAction = fileMenu->addAction(tr("&New..."));
     newAction->setShortcuts(QKeySequence::New);
     printAction = fileMenu->addAction(tr("&Print..."), this, SLOT(printFile()));
     printAction->setShortcuts(QKeySequence::Print);
     printAction->setEnabled(false);
4.
Order Form Widget閲屼富紿楀彛灝辨槸QTabWidget
鍏朵笅鏄劇ず紿楀彛鏄竴涓猀TextEdit錛岄氳繃鍒╃敤QTextCursor QTextFrame絳夊仛鐨勯潪甯稿ソ鐪?br />鍥犱負榪欎釜鎺掔増涔嬪墠瀹屽叏涓嶇煡閬撴庝箞鍘諱綔錛屼唬鐮佹秹鍙婁簡寰堝鐨勭被錛堥兘寰堢畝鍗曠殑鎺ュ彛錛夛紝鎵浠ヨ窡鐫浠g爜鍋氫簡涓閬嶆敞閲婂涔犱簡涓?br />     QTextCursor cursor(editor->textCursor());
     cursor.movePosition(QTextCursor::Start);//鍙栧緱鎸囬拡騫舵斁鍦ㄦ渶寮濮嬬殑浣嶇疆
     QTextFrame *topFrame = cursor.currentFrame();//Note that topFrame is the editor's top-level frame and is not shown in the document structure.
     QTextFrameFormat topFrameFormat = topFrame->frameFormat();
     topFrameFormat.setPadding(16);//璁劇疆鍐呭鐨勮竟璺濓紝鍘繪帀鍚庡姣斾笅

     topFrame->setFrameFormat(topFrameFormat);

     QTextCharFormat textFormat;
     QTextCharFormat boldFormat;
     boldFormat.setFontWeight(QFont::Bold);//璁劇疆瀛椾綋錛屼竴浼氫細鐢ㄥ埌

     QTextFrameFormat referenceFrameFormat;
     referenceFrameFormat.setBorder(1);
     referenceFrameFormat.setPadding(8);
     referenceFrameFormat.setPosition(QTextFrameFormat::FloatRight);//璇ュ彞浣垮緱鏄劇ず浣嶇疆浠庡彸杈瑰紑濮嬶紝鏀規垚Left鍚庡姣斾笅

     referenceFrameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 40));//QTextLength鏈変笁縐嶇被鍨嬶紝鍚箟濡備笅
 Constant Value Description
 QTextLength::VariableLength 0 The width of the object is variable
 QTextLength::FixedLength 1 The width of the object is fixed
 QTextLength::PercentageLength 2 The width of the object is in percentage of the maximum width
     cursor.insertFrame(referenceFrameFormat);//鍏充簬璇ュ彞鐨勪粙緇?br /> QTextFrame * QTextCursor::insertFrame ( const QTextFrameFormat & format )
 Inserts a frame with the given format at the current cursor position(), moves the cursor position() inside the frame, and returns the frame.

 If the cursor holds a selection, the whole selection is moved inside the frame.
 娉ㄦ剰緇欑殑鍙傛暟鏄疩TextFramFormat錛岃繑鍥炲兼槸QTextFrame錛屽厜鏍囦細縐誨姩鍒拌Frame鍐?/p>


     cursor.insertText("A company", boldFormat);
     cursor.insertBlock();//鎹㈣
     cursor.insertText("321 City Street");
     cursor.insertBlock();
     cursor.insertText("Industry Park");
     cursor.insertBlock();
     cursor.insertText("Another country");


     cursor.setPosition(topFrame->lastPosition());

     cursor.insertText(name, textFormat);
     QString line;
     foreach (line, address.split("\n")) {
         cursor.insertBlock();
         cursor.insertText(line);
     }//鍏夋爣琚噸鏂扮Щ鍔ㄥ洖鏉ュ茍涓斿啓鍏ame address

     cursor.insertBlock();
     cursor.insertBlock();//twice錛屼竴嬈¤〃紺烘崲琛岋紝涓ゆ鎵嶄細浜х敓涓涓┖琛?/p>

     QDate date = QDate::currentDate();
     cursor.insertText(tr("Date: %1").arg(date.toString("d MMMM yyyy")),
                       textFormat);//鍙栨棩鏈燂紝insert銆傘傘?br />     cursor.insertBlock();

     QTextFrameFormat bodyFrameFormat;
     bodyFrameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 100));
     cursor.insertFrame(bodyFrameFormat);
     cursor.insertText(tr("I would like to place an order for the following "
                          "items:"), textFormat);
     cursor.insertBlock();
     cursor.insertBlock();//nserts standard text into the order form.

//鎺ヤ笅鏉ユ槸涓涓?br />//A QTextTableFormat object, orderTableFormat, is used to hold the type of item and the quantity ordered.
//鐢ㄦ潵瀛樺偍orderItems鍙婂叾鏁伴噺
     QTextTableFormat orderTableFormat;
     orderTableFormat.setAlignment(Qt::AlignHCenter);
     QTextTable *orderTable = cursor.insertTable(1, 2, orderTableFormat);

     QTextFrameFormat orderFrameFormat = cursor.currentFrame()->frameFormat();
     orderFrameFormat.setBorder(1);
     cursor.currentFrame()->setFrameFormat(orderFrameFormat);
//棰樺錛氬叧浜嶲TextTable鐨凷pacing鍜?font>Padding
鍦≦TextTable綾葷殑浠嬬粛浜嗘湁涓浘

//鎰熻padding鍗充負澶栧洿鐨勮竟璺濓紝spacing鍗充負鍐呴儴杈硅窛
     cursor = orderTable->cellAt(0, 0).firstCursorPosition();
     cursor.insertText(tr("Product"), boldFormat);
     cursor = orderTable->cellAt(0, 1).firstCursorPosition();
     cursor.insertText(tr("Quantity"), boldFormat);
//娣誨姞姣忓垪鐨勬爣棰?font>P
Quantity
//涓嶈繃榪欐牱娣誨姞鍑烘潵鐨刢ell鏄彲浠ュ湪鐣岄潰涓婁慨鏀圭殑錛屽浣曢槻姝㈣繖鐐癸紵
//editor->setReadOnly(true);浼氫嬌鏁翠釜欏甸潰涓嶅彲緙栬緫錛屾墍浠ヤ笉鍙敤

 for (int i = 0; i < orderItems.count(); ++i) {
         QPair<QString,int> item = orderItems[i];
         int row = orderTable->rows();//褰撳墠琛屾暟

         orderTable->insertRows(row, 1);//鍦ㄦ渶鍚庢坊鍔犻澶栦竴琛?br />         cursor = orderTable->cellAt(row, 0).firstCursorPosition();
         cursor.insertText(item.first, textFormat);
         cursor = orderTable->cellAt(row, 1).firstCursorPosition();
         cursor.insertText(QString("%1").arg(item.second), textFormat);
     }
//鍦ㄨ繖孌典唬鐮佸悗鎴戝姞浜嗕竴孌典唬鐮佹祴璇曚簡涓?br />    cursor.insertText("This is a test");
    cursor.setPosition(cursor.currentFrame()->firstPosition());
    cursor.insertText("another test");
//

//鑷充簬cellAt錛?錛?錛夊鐨勮儗鏅鑹詫紝鏄繖涔堟敼鍙樼殑
 QTextTableCell cell = orderTable->cellAt(0,0);
    QTextCharFormat format = cell.format();
    format.setBackground(Qt::green);
    cell.setFormat(format);
//

//緇х畫紼嬪簭閲岀殑婧愪唬鐮?br />//The cursor is then moved back to topFrame's lastPosition() and more standard text is inserted.
     cursor.setPosition(topFrame->lastPosition());//榪斿洖鍒皌opFrame鐨勬紜綅緗紑濮嬭緭鍏?/p>

     cursor.insertBlock();
     cursor.insertText(tr("Please update my records to take account of the "
                          "following privacy information:"));
     cursor.insertBlock();
//Another QTextTable is inserted, to display the customer's preference regarding offers.
     QTextTable *offersTable = cursor.insertTable(2, 2);

     cursor = offersTable->cellAt(0, 1).firstCursorPosition();
     cursor.insertText(tr("I want to receive more information about your "
                          "company's products and special offers."), textFormat);
     cursor = offersTable->cellAt(1, 1).firstCursorPosition();
     cursor.insertText(tr("I do not want to receive any promotional information "
                          "from your company."), textFormat);

     if (sendOffers)
         cursor = offersTable->cellAt(0, 0).firstCursorPosition();
     else
         cursor = offersTable->cellAt(1, 0).firstCursorPosition();

     cursor.insertText("X", boldFormat);

//The cursor is moved to insert "Sincerely" along with the customer's name. More blocks are inserted for spacing purposes. The printAction is enabled to indicate that an order form can now be printed.

     cursor.setPosition(topFrame->lastPosition());
     cursor.insertBlock();
     cursor.insertText(tr("Sincerely,"), textFormat);
     cursor.insertBlock();
     cursor.insertBlock();
     cursor.insertBlock();
     cursor.insertText(name);

     printAction->setEnabled(true);
 }

鍏跺疄鎬葷粨涓嬬殑璇濓紝鏁翠釜鐣岄潰鐨勫艦鎴愪富瑕佷緷璧栦簬cursor鐨勭Щ鍔ㄥ拰insert
縐誨姩姣斿榪欐牱
cursor = offersTable->cellAt(0, 1).firstCursorPosition();
鎴栬?br />cursor.setPosition(topFrame->lastPosition());絳夌瓑
杈撳叆涓昏渚濋潬QTextCursor鐨勫洓涓嚱鏁版潵瀹屾垚鐨?br />void insertText ( const QString & text, const QTextCharFormat & format )
QTextFrame * insertFrame ( const QTextFrameFormat & format )
void insertBlock ( const QTextBlockFormat & format, const QTextCharFormat & charFormat )
QTextTable * insertTable ( int rows, int columns, const QTextTableFormat & format )
5.
鍏充簬榪欎竴鍙ュ垎鏋愪竴涓嬫祦紼?br />buttonBox 鐨?accepted錛堬級淇″彿浼氳Е鍙慏etailsDialog鐨剉erify錛堬級妲斤紝璇ユЫ鍑芥暟浼氭墽琛孌ialog鐨刟ccept() or reject()

void QDialog::accept ()   [virtual slot]
Hides the modal dialog and sets the result code to Accepted.
void QDialog::reject ()   [virtual slot]
Hides the modal dialog and sets the result code to Rejected.
void QDialog::done ( int r )   [virtual slot]
Closes the dialog and sets its result code to r. If this dialog is shown with exec(), done() causes the local event loop to finish, and exec() to return r.

//TODO錛?br />鏈鍚庣殑print鐣岄潰鐢ㄧ殑QPrintDialog鏉ュ疄鐜幫紝鏈夌┖鍙互鐪嬩笅
QTextCursor浠ュ強鐩稿叧榪橀渶瑕佽繘涓姝ュ涔?br />openDialog鍑芥暟閲岋紝涓嶆墽琛宒ialog.exec()
鐢╠ialog.show(),紿楀彛娌℃湁show鍑烘潵



izualzhy 2011-05-22 15:19 鍙戣〃璇勮
]]>QtExample__LineEdit瀛︿範絎旇http://m.shnenglu.com/izualzhy/archive/2011/05/18/146696.htmlizualzhyizualzhyWed, 18 May 2011 13:09:00 GMThttp://m.shnenglu.com/izualzhy/archive/2011/05/18/146696.htmlhttp://m.shnenglu.com/izualzhy/comments/146696.htmlhttp://m.shnenglu.com/izualzhy/archive/2011/05/18/146696.html#Feedback0http://m.shnenglu.com/izualzhy/comments/commentRss/146696.htmlhttp://m.shnenglu.com/izualzhy/services/trackbacks/146696.html鏁翠釜紿楀彛濡傚浘鎵紺?img height="364" alt="" src="http://m.shnenglu.com/images/cppblog_com/izualzhy/LineEditExample.png" width="467" border="0" />

鍏堢湅涓嬬晫闈細
鎬諱綋涓婃鏋朵嬌鐢≦GridLayout甯冨眬錛屽叡5涓狦roupBox錛屾瘡涓狦roupBox鍐呴儴渚濇棫浣跨敤QGridLayout甯冨眬錛屼竴涓猀Label錛屽Mode錛氾紝涓涓猀ComboBox錛屽PasswordEchoOnEdit錛屼竴涓猀LineEdit錛屾樉紺虹矖鐐圭殑閭d釜Echo鍗充負GroupBox鐨勬爣棰橈紝榪欐牱鏁翠釜鐣岄潰灝辮緗甇K浜嗭紝闈炲父綆鍗曪紝涔熷崄鍒嗙編瑙?/p>

鍐嶈涓嬪姛鑳斤細
5鍚凲GroupBox鍒嗗埆瀵瑰簲5鍚勬柟闈㈢殑鍔熻兘錛屼篃鍚屾椂瀵瑰簲鐫QLineEidt鐨?涓嚱鏁?br />浠庣涓涓紑濮嬭璧鳳細
鏄劇ず鏂歸潰鐨勶紝鐪嬩笅綾婚噷闈㈣嚜瀹氫箟鐨勬灇涓撅紝姝eソ瀵瑰簲Echo 鐨凜omboxBox鐨?涓夐」

enum QLineEdit::EchoMode
This enum type describes how a line edit should display its contents.

Constant Value Description
QLineEdit::Normal 0 Display characters as they are entered. This is the default.
QLineEdit::NoEcho 1 Do not display anything. This may be appropriate for passwords where even the length of the password should be kept secret.
QLineEdit::Password 2 Display asterisks instead of the characters actually entered.
QLineEdit::PasswordEchoOnEdit 3 Display characters as they are entered while editing otherwise display asterisks.
浣跨敤鐨勫嚱鏁版槸錛?br />void setEchoMode ( EchoMode )
鐩稿叧鐨勫嚱鏁版煡浜嗕笅榪樻湁榪欎袱涓?br />1.displayText : const QString
This property holds the displayed text.

If echoMode is Normal this returns the same as text(); if EchoMode is Password or PasswordEchoOnEdit it returns a string of asterisks text().length() characters long, e.g. "******"; if EchoMode is NoEcho returns an empty string, "".

By default, this property contains an empty string.
2.text : QString
This property holds the line edit's text.

Setting this property clears the selection, clears the undo/redo history, moves the cursor to the end of the line and resets the modified property to false. The text is not validated when inserted with setText().

The text is truncated to maxLength() length.

By default, this property contains an empty string.
欏懼悕鎬濅箟錛宒isplayText榪斿洖鐨勬槸鏄劇ず鍐呭錛屽鏋滄椂瀵嗙爜妯″紡錛岄偅涔堣繑鍥?*************鏄熷彿
絎簩涓細
Validator浣跨敤鐨勫嚱鏁版槸
void QLineEdit::setValidator ( const QValidator * v )
Sets this line edit to only accept input that the validator, v, will accept. This allows you to place any arbitrary constraints on the text which may be entered.

If v == 0, setValidator() removes the current input validator. The initial setting is to have no input validator (i.e. any input is accepted up to maxLength()).

See also validator(), QIntValidator, QDoubleValidator, and QRegExpValidator.
鐪嬩笅紼嬪簭閲屾槸鎬庝箞鐢ㄧ殑
     case 0:
         validatorLineEdit->setValidator(0);
         break;
     case 1:
         validatorLineEdit->setValidator(new QIntValidator(
             validatorLineEdit));
         break;
     case 2:
         validatorLineEdit->setValidator(new QDoubleValidator(-999.0,
             999.0, 2, validatorLineEdit));
     }
鏄疩LineEdit鍐呭彧鑳借緭鍏ユ暣鏁幫紝0.01綺懼害嫻偣鏁般傚彲浠ョ湅鍒拌繕鍙互鍒╃敤姝e垯鎺у埗杈撳叆鐨勫唴瀹癸細
QRegExp rx("\\d{,6}");
validatorLineEdit->setValidator(new QRegExpValidator(rx,validatorLineEdit));
榪欐牱灝卞彧鑳借緭鍏ユ渶澶?鍚勬暟瀛椾簡錛屽啀閰嶅悎鍓嶉潰鐨勫瘑鐮佹ā寮忚緭鍏ュ氨鍙互鐢ㄦ潵璁劇疆瀵嗙爜浜嗭細錛?br />絎笁涓細璁劇疆瀵歸綈鏂瑰紡
絎笁鍚勭敤鍒扮殑鍑芥暟鏄?br />void setAlignment ( Qt::Alignment flag )
alignment : Qt::Alignment
This property holds the alignment of the line edit.

Both horizontal and vertical alignment is allowed here, Qt::AlignJustify will map to Qt::AlignLeft.

By default, this property contains a combination of Qt::AlignLeft and Qt::AlignVCenter.
闈炲父綆鍗曪紝鐩存帴鐪嬫灇涓劇殑綾誨瀷
enum Qt::AlignmentFlag
flags Qt::Alignment

This enum type is used to describe alignment. It contains horizontal and vertical flags that can be combined to produce the required effect.

The TextElideMode enum can also be used in many situations to fine-tune the appearance of aligned text.

The horizontal flags are:

Constant Value Description
Qt::AlignLeft 0x0001 Aligns with the left edge.
Qt::AlignRight 0x0002 Aligns with the right edge.
Qt::AlignHCenter 0x0004 Centers horizontally in the available space.
Qt::AlignJustify 0x0008 Justifies the text in the available space.
The vertical flags are:

Constant Value Description
Qt::AlignTop 0x0020 Aligns with the top.
Qt::AlignBottom 0x0040 Aligns with the bottom.
Qt::AlignVCenter 0x0080 Centers vertically in the available space.
You can use only one of the horizontal flags at a time. There is one two-dimensional flag:

Constant Value Description
Qt::AlignCenter AlignVCenter | AlignHCenter Centers in both dimensions.
You can use at most one horizontal and one vertical flag at a time. Qt::AlignCenter counts as both horizontal and vertical.

Three enum values are useful in applications that can be run in right-to-left mode:

Constant Value Description
Qt::AlignAbsolute 0x0010 If the widget's layout direction is Qt::RightToLeft (instead of Qt::LeftToRight, the default), Qt::AlignLeft refers to the right edge and Qt::AlignRight to the left edge. This is normally the desired behavior. If you want Qt::AlignLeft to always mean "left" and Qt::AlignRight to always mean "right", combine the flag with Qt::AlignAbsolute.
Qt::AlignLeading AlignLeft Synonym for Qt::AlignLeft.
Qt::AlignTrailing AlignRight Synonym for Qt::AlignRight.
Masks:

Constant Value
Qt::AlignHorizontal_Mask AlignLeft | AlignRight | AlignHCenter | AlignJustify | AlignAbsolute
Qt::AlignVertical_Mask AlignTop | AlignBottom | AlignVCenter
Conflicting combinations of flags have undefined meanings.

The Alignment type is a typedef for QFlags<AlignmentFlag>. It stores an OR combination of AlignmentFlag values.

絎洓涓細鍙互鐢ㄦ潵鎺у埗涓浜涜緭鍏ユ牸寮忥紝鍙互鏃犻』鍊熷姪姝e垯
鐢ㄥ埌鍑芥暟涓昏鏄?br />void setInputMask ( const QString & inputMask )

鐩存帴鐪嬩粙緇?br />inputMask : QString
This property holds the validation input mask.

If no mask is set, inputMask() returns an empty string.

Sets the QLineEdit's validation mask. Validators can be used instead of, or in conjunction with masks; see setValidator().

Unset the mask and return to normal QLineEdit operation by passing an empty string ("") or just calling setInputMask() with no arguments.

The table below shows the characters that can be used in an input mask. A space character, the default character for a blank, is needed for cases where a character is permitted but not required.

Character Meaning
A ASCII alphabetic character required. A-Z, a-z.
a ASCII alphabetic character permitted but not required.
N ASCII alphanumeric character required. A-Z, a-z, 0-9.
n ASCII alphanumeric character permitted but not required.
X Any character required.
x Any character permitted but not required.
9 ASCII digit required. 0-9.
0 ASCII digit permitted but not required.
D ASCII digit required. 1-9.
d ASCII digit permitted but not required (1-9).
# ASCII digit or plus/minus sign permitted but not required.
H Hexadecimal character required. A-F, a-f, 0-9.
h Hexadecimal character permitted but not required.
B Binary character required. 0-1.
b Binary character permitted but not required.
> All following alphabetic characters are uppercased.
< All following alphabetic characters are lowercased.
! Switch off case conversion.
\ Use \ to escape the special characters listed above to use them as separators.
The mask consists of a string of mask characters and separators, optionally followed by a semicolon and the character used for blanks. The blank characters are always removed from the text after editing.

Examples:

Mask Notes
000.000.000.000;_ IP address; blanks are _.
HH:HH:HH:HH:HH:HH;_ MAC address
0000-00-00 ISO Date; blanks are space
>AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# License number; blanks are - and all (alphabetic) characters are converted to uppercase.
To get range control (e.g., for an IP address) use masks together with validators.

Access functions:

QString inputMask () const
void setInputMask ( const QString & inputMask )
See also maxLength.
鐪嬩笅紼嬪簭鐢ㄥ埌鐨勫湴鏂癸細
    switch (index) {
    case 0:
        inputMaskLineEdit->setInputMask("");
        break;
    case 1:
        inputMaskLineEdit->setInputMask("+99 99 99 99 99;_");
        break;
    case 2:
        inputMaskLineEdit->setInputMask("0000-00-00");
        inputMaskLineEdit->setText("00000000");
        inputMaskLineEdit->setCursorPosition(0);
        break;
    case 3:
        inputMaskLineEdit->setInputMask(">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#");
鍏朵腑鍒嗗彿鍚庨潰璺熺殑絎﹀彿浼氫唬鏇挎帀鍓嶉潰鐨勯偅浜涢氶厤絎?br />姣斿閫夊埌License Key 錛孮LIneEdit鍐呭鍙樹負
#####-#####-#####-#####-#####
杈撳叆鏃跺彧鑳借緭鍏ュ瓧姣嶏紝鍚屾椂-浼氳嚜鍔ㄨ煩榪囷紝涓嶅彲鏀瑰彉錛屼笉琚垹闄わ紝鎬諱箣璇曚笅灝辯煡閬撲簡鍝堝搱

5.
寰堢畝鍗曪紝璁劇疆鍐呭鏄惁鍙洿鏀?br />readOnly : bool
This property holds whether the line edit is read only.

In read-only mode, the user can still copy the text to the clipboard, or drag and drop the text (if echoMode() is Normal), but cannot edit it.

QLineEdit does not show a cursor in read-only mode.

By default, this property is false.

鍑犱釜鍑芥暟緇勫悎浣跨敤錛屽姛鑳藉緢寮哄ぇ



izualzhy 2011-05-18 21:09 鍙戣〃璇勮
]]>
QtExamples涔婽oolTips瀛︿範http://m.shnenglu.com/izualzhy/archive/2011/05/17/146601.htmlizualzhyizualzhyTue, 17 May 2011 13:30:00 GMThttp://m.shnenglu.com/izualzhy/archive/2011/05/17/146601.htmlhttp://m.shnenglu.com/izualzhy/comments/146601.htmlhttp://m.shnenglu.com/izualzhy/archive/2011/05/17/146601.html#Feedback0http://m.shnenglu.com/izualzhy/comments/commentRss/146601.htmlhttp://m.shnenglu.com/izualzhy/services/trackbacks/146601.htmlToolTips鍙互鐢ㄦ潵鍒涘緩涓夌褰㈢姸錛岃繖浜涘浘褰㈤兘鍙互鐢ㄩ紶鏍囨嫋鍔紝褰撻紶鏍囧仠鐣欏湪涓婇潰鏃訛紝榪樻湁tooltips


璇ヤ緥瀛愭湁涓や釜涓昏鐨勭被錛?br />ShapeItem is a custom widget representing one single shape item.
SortingBox inherits from QWidget and is the application's main widget.
1.SortingBox
SortingBox綾婚噷閲嶆柊瀹炵幇浜嗗緢澶歟vent錛岀敤閫斿涓嬶細
The event() function provides tooltips, the resize() function makes sure the application appears consistently when the user resizes the main widget, and the paintEvent() function displays the shape items within the SortingBox widget. The mouse event handlers are reimplemented to make the user able to move the items around.
涓変釜縐佹湁鐨勬Ы鍑芥暟鍒嗗埆瀵瑰簲鍒涘緩涓夌鍥懼艦
鍦ㄦ瀯閫犲嚱鏁伴噷璋冪敤涓変釜鍑芥暟錛?br />initialItemPosition(), initialItemColor() and createToolButton()
鐪嬪悕瀛楀氨鐭ラ亾鍦ㄥ仛浠涔堜簡
2.
瑕佹樉紺簍ooltip蹇呴』瑕佺煡閬撻紶鏍囩Щ鍔ㄤ簨浠訛紝榛樿鍦ㄤ笉鎸変笅閿椂鏄笉璁板綍榧犳爣杞ㄨ抗鐨勶紝鍥犳闇瑕佽緗笅
setMouseTracking(true);
To be able to show the appropiate tooltips while the user is moving the cursor around, we need to enable mouse tracking for the widget.

If mouse tracking is disabled (the default), the widget only receives mouse move events when at least one mouse button is pressed while the mouse is being moved. If mouse tracking is enabled, the widget receives mouse move events even if no buttons are pressed.
3.濡備綍鐢誨嚭鐨勪笁瑙掑艦錛岀煩褰紝妞渾
鐭╁艦錛屾き鍦嗙敤QPainter鐨勫嚱鏁板氨鍙互浜嗭紝涓夎褰㈢敤drawLine鐢諱笁嬈★紝姣忔鐢諱笁瑙掑艦鏄笉鏄お璐瑰姴浜嗛偅錛熸垨鑰呭鏋滈亣鍒板叾浠栦笉瑙勫垯鐨勫浘褰紝鎬庝箞鐢誨嚭鏉ョ殑鍛紵
榪欓噷灝辯敤鍒頒簡QPainterPath綾諱簡
鍏堢湅涓猘ddRect鍑芥暟

鍐嶇湅涓猘ddEllipse

鍐嶆潵涓礉娉藉皵鏇?img height="263" alt="" src="http://m.shnenglu.com/images/cppblog_com/izualzhy/QPainterPath__cubicTo.png" width="731" border="0" />綰跨殑

鍏堝畾涔夋洸綰匡紝鐒跺悗鐢≦Painter::drawPath()灝監K浜?br />鏈変竴涓棶棰樻槸錛宒rawPath錛堬級騫朵笉鑳芥寚瀹歱osition
鐪嬩笅瀹氫箟


鍥犳鍦ㄦ兂瑕佸湪鏌愪釜鐐瑰紑濮嬬敾鍑烘兂瑕佺殑鏇茬嚎錛屽厛縐誨姩鍧愭爣緋?br />    foreach (ShapeItem shapeItem, shapeItems) {
//! [8] //! [9]
        painter.translate(shapeItem.position());
//! [9] //! [10]
        painter.setBrush(shapeItem.color());
        painter.drawPath(shapeItem.path());
        painter.translate(-shapeItem.position());
    }
榪欎箞鍋氱殑瑙i噴錛?br />The painter will by default draw all the shape items at position (0,0) in the SortingBox widget. The QPainter::translate() function translates the coordinate system by the given offset, making each shape item appear at its defined position. But remember to translate the coordinate system back when the item is drawn, otherwise the next shape item will appear at a position relative to the item we drawed last.
4.濡備綍瀹炵幇縐誨姩錛?br />鎬濊冧竴涓嬶紝鑲畾鏄湪mousePressEvent,mouseMoveEvent,moutReleaseEvent涓婁慨鏀廣?br />鑰屼笖璇存槸縐誨姩錛屽叾瀹炴槸瀹屽叏閲嶇粯浜嗕竴閬嶆暣涓獁idget銆?br />閭d箞錛屾庝箞鐭ラ亾褰撳墠榧犳爣鐐瑰湪鍝釜鍥懼艦涓婂憿錛?br />鍏跺疄榪欎釜闂姣斾箣鍓嶆垜鎯崇殑瑕佺畝鍗曪細
紼嬪簭鍒╃敤浜嗗涓嬪嚱鏁幫細
int SortingBox::itemAt(const QPoint &pos)
{
    for (int i = shapeItems.size() - 1; i >= 0; --i) {
        const ShapeItem &item = shapeItems[i];
        if (item.path().contains(pos - item.position()))
            return i;
    }
    return -1;
}
寰幆閬嶅巻姣忎釜shapwItem錛岄嗗簭閬嶅巻鐨勫師鍥犳槸褰撹繖涓偣鍦ㄥ涓猻hapeitem涓婃椂錛岃繑鍥炴渶涓婇潰鐨勪竴涓紝鍒╃敤QPainterPath鐨勫嚱鏁癱ontains
bool QPainterPath::contains ( const QPointF & point ) const
Returns true if the given point is inside the path, otherwise returns false.
璁板綍榧犳爣縐誨姩鍓嶅悗鐨勫亸縐婚噺錛岃緗粰褰撳墠鐨剆hapeItem錛岀劧鍚巙pdate錛堬級閲嶇粯銆?br />鍊煎緱娉ㄦ剰鐨勬槸瀵箂hapeItems錛屽嵆瀛樺偍鍥懼艦鐨勫垪琛ㄧ殑淇敼錛屽亣璁捐浠ュ姩鐨勫浘褰㈠湪鍒楄〃閲岀儲寮曟槸index錛岃皟鐢ㄤ笅鍒楄鍙?br /> shapeItems.move(index, shapeItems.size() - 1);
鏄綋鍓嶄慨鏀逛綅緗殑鍥懼艦璺戝埌鍒楄〃鏈鍚庛?br />5.濡備綍瀹炵幇toolTops鐨勶紵
bool SortingBox::event(QEvent *event)
{
//! [5] //! [6]
    if (event->type() == QEvent::ToolTip) {
        QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
        int index = itemAt(helpEvent->pos());
        if (index != -1) {
            QToolTip::showText(helpEvent->globalPos(), shapeItems[index].toolTip());
        } else {
            QToolTip::hideText();
            event->ignore();
        }

        return true;
    }
    return QWidget::event(event);
}
鐩存帴鐪婹t assistant鐨勮В閲?br />If the type is QEvent::ToolTip, we cast the event to a QHelpEvent, otherwise we propagate the event using the QWidget::event() function.

The QHelpEvent class provides an event that is used to request helpful information about a particular point in a widget.

For example, the QHelpEvent::pos() function returns the event's position relative to the widget to which the event is dispatched. Here we use this information to determine if the position of the event is contained within the area of any of the shape items. If it is, we display the shape item's tooltip at the position of the event. If not, we hide the tooltip and explicitly ignore the event. This makes sure that the calling code does not start any tooltip specific modes as a result of the event. Note that the QToolTip::showText() function needs the event's position in global coordinates provided by QHelpEvent::globalPos().



izualzhy 2011-05-17 21:30 鍙戣〃璇勮
]]>
銆愯漿銆慟Painter::begin: Widget painting can only begin as a result of a paintEventhttp://m.shnenglu.com/izualzhy/archive/2011/03/21/142414.htmlizualzhyizualzhyMon, 21 Mar 2011 14:00:00 GMThttp://m.shnenglu.com/izualzhy/archive/2011/03/21/142414.htmlhttp://m.shnenglu.com/izualzhy/comments/142414.htmlhttp://m.shnenglu.com/izualzhy/archive/2011/03/21/142414.html#Feedback0http://m.shnenglu.com/izualzhy/comments/commentRss/142414.htmlhttp://m.shnenglu.com/izualzhy/services/trackbacks/142414.html鍦≦t閲岋紝榛樿鎯呭喌涓嬭浣跨敤QPainter鐢誨浘蹇呴』鍦╬aintEvent()鍑芥暟閲岋紝濡傛灉鍦ㄥ叾瀹冨湴鏂圭殑璇濓紝榪愯鏃朵細鎻愮ず濡備笅閿欒
QPainter::begin: Widget painting can only begin as a result of a paintEvent
瑕侀伩鍏嶈繖涓棶棰樺彲浠ヨ緗綘瑕佺敾鍥劇殑閭d釜widget鐨勪竴涓睘鎬э紝鍔犱笂綾諱技榪欐牱鐨勪唬鐮乼his->setAttribute(Qt::WA_PaintOutsidePaintEvent);
灝卞彲浠ヤ簡銆?br>qpainter.cpp 浠g爜閲岀浉搴斿疄鐜伴昏緫錛屽彲浠ョ湅涓嬮潰
   1081     switch (pd->devType()) {
   1082         case QInternal::Widget:
   1083         {
   1084             const QWidget *widget = static_cast(pd);
   1085             Q_ASSERT(widget);
   1086
   1087             if(!d->engine->hasFeature(QPaintEngine::PaintOutsidePaintEvent)
   1088                && !widget->testAttribute(Qt::WA_PaintOutsidePaintEvent)
   1089                && !widget->testAttribute(Qt::WA_WState_InPaintEvent)) {
   1090                 qWarning("QPainter::begin: Widget painting can only begin as a "
   1091                          "result of a paintEvent");
   1092                 return false;
   1093             }
   1094             break;
   1095         }

izualzhy 2011-03-21 22:00 鍙戣〃璇勮
]]>
鍏充簬Qt閲岀殑globalPos鍜宲oshttp://m.shnenglu.com/izualzhy/archive/2011/03/21/142408.htmlizualzhyizualzhyMon, 21 Mar 2011 13:11:00 GMThttp://m.shnenglu.com/izualzhy/archive/2011/03/21/142408.htmlhttp://m.shnenglu.com/izualzhy/comments/142408.htmlhttp://m.shnenglu.com/izualzhy/archive/2011/03/21/142408.html#Feedback0http://m.shnenglu.com/izualzhy/comments/commentRss/142408.htmlhttp://m.shnenglu.com/izualzhy/services/trackbacks/142408.html鏂板緩涓涓獥鍙g▼搴忥紝鐒跺悗鍒涘緩涓涓猀Menu瀵硅薄銆傚湪鏋勯犲嚱鏁伴噷鍒濆鍖?br>menu = new QMenu("menu", this); //menu鍦ㄥご鏂囦歡澹版槑
QAction *action = new QAction(tr("1111"), this); //涓轟嬌鐩綍杈冨ぇ錛岃兘鐪嬭錛屾垜浠坊鍔犱竴涓猘ction
menu->addAction(action);

鐒跺悗鍦╩ousePressEvent閲岀湅鍒版晥鏋?br>void Dialog::mousePressEvent(QMouseEvent *e)
{
    if(e->button() == Qt::RightButton) //榧犳爣鍙抽敭銆傞伩鍏嶆棤娉曞叧鎺夌獥鍙?br>    {
        QPoint p(0, 0);
        //menu->exec(p); //嫻嬭瘯鐢紝鍧愭爣鐩稿浜庢闈?br>        menu->exec(e->globalPos()); //鍧愭爣鐩稿浜庣獥鍙?br>        //menu->exec(e->pos()); //鍧愭爣鐩稿浜庢闈?br>    }
}

鍙互鐪嬪埌錛宲os涓嶇紿楀彛鎬庢牱縐誨姩錛宮enu鎬繪槸鍑虹幇鍦ㄧ浉鍚岀殑鍦版柟銆俫lobalPos鐩稿浜庣獥鍙o紝璺熺潃紿楀彛縐誨姩.

pos涓嶇紿楀彛鎬庢牱縐誨姩錛宮enu鎬繪槸鍑虹幇鍦ㄧ浉鍚岀殑鍦版柟銆?br>鍋囪鎴戜滑涓鐩寸偣鍑葷殑鏄獥鍙e彸涓婅錛宮enu鎬繪槸鍑虹幇鍦ㄥ悓鏍風殑鍦版柟銆備篃灝辨槸綾諱技浜庢墽琛宮enu->exec(QPoint(1000,0))
鎵浠鐨勫兼病鍙橈紝浣嗙浉瀵逛簬妗岄潰鎴戜滑鐐圭殑鍦版柟宸茬粡鍙樹簡錛屽彧鏄浉瀵圭獥鍙g殑鍧愭爣p涓鐩存槸(1000,0)錛屾墍浠os鏄浉瀵圭獥鍙g殑銆傘傘?br>globalPos鐩稿浜庣獥鍙o紝璺熺潃紿楀彛縐誨姩銆備笉璁烘垜鐐瑰摢鑿滃崟灝卞湪鍝猻how錛屾墍浠ユ槸鐩稿妗岄潰鐨勶紝瑕佷笉鍙玤lobal鍛~


izualzhy 2011-03-21 21:11 鍙戣〃璇勮
]]>
Qt Example & Codecs Examplehttp://m.shnenglu.com/izualzhy/archive/2011/03/18/142171.htmlizualzhyizualzhyFri, 18 Mar 2011 13:49:00 GMThttp://m.shnenglu.com/izualzhy/archive/2011/03/18/142171.htmlhttp://m.shnenglu.com/izualzhy/comments/142171.htmlhttp://m.shnenglu.com/izualzhy/archive/2011/03/18/142171.html#Feedback0http://m.shnenglu.com/izualzhy/comments/commentRss/142171.htmlhttp://m.shnenglu.com/izualzhy/services/trackbacks/142171.htmlCodecs Example
瀛︿範榪欎釜渚嬪瓙涓昏鏄兂浜嗚В涓嬪湪鏂囨湰澶勭悊鏃跺浣曠‘瀹氭枃鏈殑緙栫爜鏍煎紡闂锝烇綖
Qt assistant閲屽彧鐢ㄤ竴鍙ヨ瘽浠嬬粛浜嗕笅锝?br>The Codecs example demonstrates the principles behind importing and exporting text using codecs to ensure that characters are encoded properly, avoiding loss of data and retaining the correct symbols used in various scripts
鎬葷粨涓鍙ヨ瘽錛屽氨鏄瀛︿範QTextCodec綾伙紝鐣岄潰嬈′箣锝烇綖
ps:
鎵撳紑榪欎釜渚嬪瓙鐪嬪埌saveAs鑿滃崟鍚庨潰閭d箞澶氱殑Action灝辨兂鍒板垰瀛︾殑QOject::sender()浜嗭綖锝?/p>

璇ヤ緥瀛愮敱涓や釜涓昏鐨勭被
MainWindow錛歱ublic QMainWindow
PreviewForm: public QDialog
1.
鏂囨湰杈撳叆鐣岄潰浣跨敤鐨凲TextEdit錛岄氳繃 setCentralWidget(textEdit);鑰岃瀹氫負MainWindow鐨勪富紿楀彛錛屽簲璇ユ槸寰堢啛鎮夎繖涓簡锝烇綖
QTextEdit鏈変竴涓睘鎬ф槸
enum QTextOption::WrapMode
This enum describes how text is wrapped in a document.

Constant Value Description
QTextOption::NoWrap 0 Text is not wrapped at all.
QTextOption::WordWrap 1 Text is wrapped at word boundaries.
QTextOption::ManualWrap 2 Same as QTextOption::NoWrap
QTextOption::WrapAnywhere 3 Text can be wrapped at any point on a line, even if it occurs in the middle of a word.
QTextOption::WrapAtWordBoundaryOrAnywhere 4 If possible, wrapping occurs at a word boundary; otherwise it will occur at the appropriate point on the line, even in the middle of a word.
琛ㄧず鍦ㄨ鏈浣曟崲琛屾垨鑰呬笉鎹㈣銆?br>2.
鐢變簬緙栫爜鏂瑰紡寰堝錛屼負浜嗕嬌鑿滃崟鐪嬩笂鍘葷編瑙備簺錛岃璁劇疆涓涓嬮偅浜涘尮閰嶅埌涓鍧楋紝浜庢槸鐢ㄥ埌浜哘RegExp
榪欓噷鐢ㄧ殑姝e垯鏄緢綆鍗曠殑錛屾垜涔熷彧鐪嬩簡涓嬬敤鍒扮殑涓や釜鍑芥暟
A銆?br>bool QRegExp::exactMatch ( const QString & str ) const
Returns true if str is matched exactly by this regular expression; otherwise returns false. You can determine how much of the string was matched by calling matchedLength().

For a given regexp string R, exactMatch("R") is the equivalent of indexIn("^R$") since exactMatch() effectively encloses the regexp in the start of string and end of string anchors, except that it sets matchedLength() differently.

For example, if the regular expression is blue, then exactMatch() returns true only for input blue. For inputs bluebell, blutak and lightblue, exactMatch() returns false and matchedLength() will return 4, 3 and 0 respectively.
榪欎釜琛ㄧず鐨勬槸瑕佸畬鍏ㄥ尮閰嶏紝鑰屼笉鏄粠涓棿寮濮嬨傜被浼間簬Python閲屾鍒欒〃杈懼紡鐨剆earch()鍜宮atch錛堬級
B銆?br>QString QRegExp::cap ( int nth = 0 ) const
Returns the text captured by the nth subexpression. The entire match has index 0 and the parenthesized subexpressions have indexes starting from 1 (excluding non-capturing parentheses).
閫氳繃鍦╮x閲屾坊鍔犳嫭鍙鋒煡鐪嬭繑鍥炲鹼綖锝?br>鍖歸厤濂戒簡涔嬪悗浼氬悓鏃朵駭鐢熶竴涓猧nt綾誨瀷鐨剅ank鍊鹼紝鍔犲湪codec鐨勫悕瀛楀墠浣滀負key錛宑odec浣滀負value緇勬垚QMap
3.
鍦╬rivate閲屽畾涔変簡QList<QTextCodec *> codecs;
灝嗗垰瀹氫箟鐨凲Map閫氳繃values錛堬級鍑芥暟璧嬬粰璇ョ鏈夊彉閲忥紝娉ㄦ剰values錛堬級鍑芥暟鐨勬弿榪幫細
QList<T> QMap::values () const
Returns a list containing all the values in the map, in ascending order of their keys. If a key is associated with multiple values, all of its values will be in the list, and not just the most recently inserted one.
浼氭湁涓涓『搴忕殑闂錛岃繖涔熸槸鎴戜滑娣誨姞rank鐨勫師鍥犱簡锝烇綖
榪欐牱璧嬪間箣鍚庯紝QList codecs閲屽氨鏄帓搴忎箣鍚庣殑浜嗭綖锝?br>寰楀厛蹇欏伐浣滅殑涓滆タ浜嗭紝鏈夌┖瑕佸啀鐮旂┒涓?/p>


 



izualzhy 2011-03-18 21:49 鍙戣〃璇勮
]]>
Qt Example & CodeEditor Examplehttp://m.shnenglu.com/izualzhy/archive/2011/03/18/142170.htmlizualzhyizualzhyFri, 18 Mar 2011 13:48:00 GMThttp://m.shnenglu.com/izualzhy/archive/2011/03/18/142170.htmlhttp://m.shnenglu.com/izualzhy/comments/142170.htmlhttp://m.shnenglu.com/izualzhy/archive/2011/03/18/142170.html#Feedback0http://m.shnenglu.com/izualzhy/comments/commentRss/142170.htmlhttp://m.shnenglu.com/izualzhy/services/trackbacks/142170.html榪欎釜渚嬪瓙鍏跺疄寰堝娌$湅鎳傜殑錛屽厛鍐欑偣鐪嬫噦鐨勯儴鍒嗗仛涓嬬瑪璁幫綖锝炵壒鍒槸QPlainTextEditor鐨勬瘡涓琛岀殑楂樺害鏄庝箞涓庢樉紺鴻鍙風殑widget瀵瑰簲鐨勮繖涔堝悎鐞嗙殑銆?br>CodeEditor Example鐢變袱涓被緇勬垚
LineNumberArea + CodeEdit
CodeEdit璐熻矗鏂囧瓧杈撳叆錛孡ineNumberArea鍒欒礋璐h鏁扮殑鏄劇ず銆備袱鑰呬箣闂寸粍鎴愬叧緋繪槸
We paint the line numbers on this widget錛圠ineNumberArea錛? and place it over the CodeEditor's viewport()'s left margin area.
濡傛灉鎴戜滑setViewportMargins錛堬級璁懼畾浜唌argin錛孡ineNumberArea鐨刾arent鍙堟槸CodeEdit錛岄偅涔圠ineNumberArea鑷姩鐢熸垚鍦╩argin涓婏紵
鍦ㄤ互涓嬩笁縐嶆儏鍐典笅錛岄渶瑕乨raw LineNumberArea錛堝彧鏈夎繖涓兂娓呮浜嗘墠鑳藉啓濂戒俊鍙峰拰妲介樋锝烇綖鎴戞槸娌℃兂鏄庣櫧銆傘傘傦級
1.when the number of lines in the editor changes
2.when the editor's viewport() is scrolled
3.Of course, it is also done when the editor's size changes
鍏堣涓媣iewport
viewport閮ㄥ垎灝辨槸涓葷獥鍙g敤浜庤緭鍏ョ殑錛屽洓鍛ㄦ槸verticalScrollBar鎴栬卙orizontalScrollBar銆傚綋鐒朵篃鍙互閫氳繃setViewportMargins()鏉ュ湪viewport鍛ㄥ洿鍏堝姞涓浜涚┖鐧斤綖锝?br>鍏蜂綋鐨凲t鏂囨。閲岃繖涔堜粙緇嶇殑錛?br>The QAbstractScrollArea widget provides a scrolling area with on-demand scroll bars.

QAbstractScrollArea is a low-level abstraction of a scrolling area. The area provides a central widget called the viewport, in which the contents of the area is to be scrolled (i.e, the visible parts of the contents are rendered in the viewport).

Next to the viewport is a vertical scroll bar, and below is a horizontal scroll bar. When all of the area contents fits in the viewport, each scroll bar can be either visible or hidden depending on the scroll bar's Qt::ScrollBarPolicy. When a scroll bar is hidden, the viewport expands in order to cover all available space. When a scroll bar becomes visible again, the viewport shrinks in order to make room for the scroll bar.

It is possible to reserve a margin area around the viewport, see setViewportMargins(). The feature is mostly used to place a QHeaderView widget above or beside the scrolling area. Subclasses of QAbstractScrollArea should implement margins.1

1.
fontMetrics().width(QLatin1Char('9'))
榪斿洖鍙湁涓涓瓧絎?#8216;9’鏃剁殑鍚堢悊瀹藉害锝烇綖
2.
void QAbstractScrollArea::setViewportMargins ( int left, int top, int right, int bottom )
榪欎釜鍑芥暟涓鐩村紕娣蜂簡錛岃鍑芥暟瀹為檯涓婃槸鍒涘緩浜嗗洓涓猰argin
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
渚嬪璇ヨ鍙ュ嵆鏄湪宸﹁竟鍒涘緩涓涓猰argin锝烇綖铏界劧鍙紶榪涗簡涓涓猧nt鍊鹼紝浣唙iewport鍛ㄥ洿鐨刴argin鏄幆緇曟暣涓獀iewport鐨勶紝鎵浠ュ彟涓鏉¤竟鏄浐瀹氬ぇ灝忕殑錛堟棭鎯沖埌榪欑偣灝變笉浼氱湅涓嶆槑鐧戒簡銆傘傘傦級
 

 

 

 

 

 

 

 



izualzhy 2011-03-18 21:48 鍙戣〃璇勮
]]>
Qt Example &Shape Analog Clock examplehttp://m.shnenglu.com/izualzhy/archive/2011/03/18/142168.htmlizualzhyizualzhyFri, 18 Mar 2011 13:39:00 GMThttp://m.shnenglu.com/izualzhy/archive/2011/03/18/142168.htmlhttp://m.shnenglu.com/izualzhy/comments/142168.htmlhttp://m.shnenglu.com/izualzhy/archive/2011/03/18/142168.html#Feedback0http://m.shnenglu.com/izualzhy/comments/commentRss/142168.htmlhttp://m.shnenglu.com/izualzhy/services/trackbacks/142168.html 

Shape Analog Clock example
1.
Qt::FramelessWindowHint鍙互浣跨獥鍙e幓鎺夊叧闂?鏈澶у寲 鏈灝忓寲絳夛紝浣嗘槸闇瑕侀噸鏂拌嚜瀹氫箟move絳変簨浠?br>璇lag鍦≦t閲屼粙緇嶏細
Produces a borderless window. The user cannot move or resize a borderless window via the window system
鍦ㄨ繖涓緥瀛愰噷浜庢槸鎴戜滑闇瑕佽嚜瀹氫箟mouseMoveEvent,mousePressEvent錛屽師鏂囧涓嬶細
We inform the window manager that the widget is not to be decorated with a window frame by setting the Qt::FramelessWindowHint flag on the widget. As a result, we need to provide a way for the user to move the clock around the screen.
璇ヤ緥瀛愬疄鐜板悗鍙互鍦ㄦ闈笂鎷栧姩涓涓被浼間簬琛ㄧ殑widget錛屽悓鏃舵病鏈夎竟妗嗭紝寰堢編瑙傦紝閭d箞瀹氫箟mouseMoveEvent()鏃訛紝鎴戜滑濡備綍紜畾璇idget搴斿綋move鍒頒粈涔堝湴鏂瑰憿錛?br>渚嬪瓙閲屽畾涓涓竴涓猵rivate data 錛?br>QPoint dragPosition;
鍦╩ousePressEvent閲?br>dragPosition = event->globalPos() - frameGeometry().topLeft();
鍦╩ouseMoveEvent閲?br>move(event->globalPos() - dragPosition);
鍗蟲妸榧犳爣鎸変笅鏃剁殑浣嶇疆涓庢帶浠跺乏涓婄殑鍧愭爣璺濈浣滀負涓涓亸縐婚噺

鍘熸枃浠嬬粛濡備笅錛?br>If the left mouse button is pressed over the widget, we record the displacement in global (screen) coordinates between the top-left position of the widget's frame (even when hidden) and the point where the mouse click occurred. This displacement will be used if the user moves the mouse while holding down the left button. Since we acted on the event, we accept it by calling its accept() function.
娉ㄦ剰榪欓噷鏃秅lobalPos()~~
2.sizeHint()
鍒氬紑濮嬫病鏈夊紕鎳備負浠涔堣瀹氫箟sizeHint()
鍘繪帀鍚庡姣斾笅鍥懼儚鍙戠幇鍥懼ぇ浜嗕笉灝戯紝鎵嶆槑鐧藉湪鍥懼儚鏈寚瀹氬ぇ灝忔椂絎竴嬈how鐨勬椂鍊欎細鑷姩璋冪敤sizeHint錛堬級
渚嬪瓙涓鏄庡涓?br>Finally, we implement the sizeHint() for the widget so that it is given a reasonable default size when it is first shown:
鍘繪帀sizeHint鍑芥暟鐨?br>鐢ㄤ簡sizeHint鐨勫氨姣旇緝緹庤浜?br>3.mask
閭d箞濡備綍鏄獥鍙e憟鐜頒負涓涓渾褰㈢殑鍛紵
鍏跺疄紿楀彛榪樻槸鐭╁艦鐨勶紝涓嶈繃閫氳繃mask璁句負涓閮ㄥ垎鍙錛屼竴閮ㄥ垎閫忔槑浜?br>setMask鏈変袱縐嶅艦寮忥紝涓嶈繃浣滅敤閮芥槸綾諱技鐨?br>void QWidget::setMask ( const QBitmap & bitmap )
Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible
void QWidget::setMask ( const QRegion & region )
Causes only the parts of the widget which overlap region to be visible.
鍗蟲槸鍖哄煙鍐呭彲瑙侊紝鍏朵綑涓嶅彲瑙併?br>鍙﹀涓涓叧浜庨忔槑鎬х殑鍑芥暟涓?br>void setWindowOpacity ( qreal level )
windowOpacity : double
This property holds the level of opacity for the window.
The valid range of opacity is from 1.0 (completely opaque) to 0.0 (completely transparent).
璇ュ嚱鏁版帶鍒剁殑鏄暣涓獁idget鐨勯忔槑鎬э綖
濡傛灉setMask錛堬級涓巗etWindowOpacity錛堬級涓璧風敤浜嗭紝QREgion澶栦粛鏄忔槑鐨勶紝涓嶈繃mask鐨勫尯鍩熼忔槑搴﹀洜涓簊etWindowOpacity錛堬級鏀瑰彉浜嗐?br>榪欐槸鎴戠敤浜嗚鍑芥暟涔嬪悗鐨勪緥瀛?br> 鍙互鐪嬪埌鍙樺緱閫忔槑浜?br>榪欏紶鍥懼姣斿氨鏇存槑鏄句簡
4.濡備綍鎸変笅榧犳爣鍙抽敭寮瑰嚭Action鐨勶紵
鐩存帴new涓涓猀Action鍑烘潵鐒跺悗add灝辮浜嗭綖锝?br>浼拌鏄洜涓哄湪榪欑widget涓嬫病鏈夊叾浠栧湴鏂規斁灝遍粯璁ゆ斁鍦ㄥ彸閿噷浜嗭紝闇瑕佽繘涓姝ュ涔犳墠鑳界‘瀹氾綖锝?/p>

izualzhy 2011-03-18 21:39 鍙戣〃璇勮
]]>
Qt Example & Scribble Examplehttp://m.shnenglu.com/izualzhy/archive/2011/03/18/142167.htmlizualzhyizualzhyFri, 18 Mar 2011 13:33:00 GMThttp://m.shnenglu.com/izualzhy/archive/2011/03/18/142167.htmlhttp://m.shnenglu.com/izualzhy/comments/142167.htmlhttp://m.shnenglu.com/izualzhy/archive/2011/03/18/142167.html#Feedback0http://m.shnenglu.com/izualzhy/comments/commentRss/142167.htmlhttp://m.shnenglu.com/izualzhy/services/trackbacks/142167.html 

鍦≦t4.0閲孲cribble example閲岀敾綰挎潯鏄厛draw鍦ㄤ竴涓猧mage涓婏紝image鍦ㄩ氳繃drawImage鐢誨埌widget涓婏紝緇欏嚭浜嗚繖鏍風殑鐞嗙敱
At this point, you might wonder why we don't just draw directly onto the widget instead of drawing in a QImage and copying the QImage onto screen in paintEvent(). There are at least three good reasons for this:

The window system requires us to be able to redraw the widget at any time. For example, if the window is minimized and restored, the window system might have forgotten the contents of the widget and send us a paint event. In other words, we can't rely on the window system to remember our image.
Qt normally doesn't allow us to paint outside of paintEvent(). In particular, we can't paint from the mouse event handlers. (This behavior can be changed using the Qt::WA_PaintOnScreen widget attribute, though.)
If initialized properly, a QImage is guaranteed to use 8-bit for each color channel (red, green, blue, and alpha), whereas a QWidget might have a lower color depth, depending on the monitor configuration. This means that if we load a 24-bit or 32-bit image and paint it onto a QWidget, then copy the QWidget into a QImage again, we might lose some information.

image姣攚idget瑕佺◢澶т竴鐐癸紝鐞嗙敱濡備笅
When the user starts the Scribble application, a resize event is generated and an image is created and displayed in the scribble area. We make this initial image slightly larger than the application's main window and scribble area, to avoid always resizing the image when the user resizes the main window (which would be very inefficient). But when the main window becomes larger than this initial size, the image needs to be resized.

褰撻渶瑕侀噸緇樼殑浜嬩歡paintEvent鏃訛紝閫氳繃浼犵粰update錛堬級涓涓弬鏁板彲鑳戒細鎻愰珮鏁堢巼錛屽綋鐒跺墠鎻愭槸浣犵煡閬撹繖涓弬鏁?br>We could call the update() function with no parameter, but as an easy optimization we pass a QRect that specifies the rectangle inside the scribble are needs updating, to avoid a complete repaint of the widget.
渚嬪榪欓噷浼犲叆鐨勬槸錛岄紶鏍囨柊鐢葷殑綰挎 涓庣瑪鐨勫ぇ灝忕粍鎴愮殑涓涓煩褰㈠尯鍩熴傝繖鏍峰彧浼氶噸鏂扮粯鍒惰繖閲屼簡锝烇綖
 Painter painter(&image);
     painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap,
                         Qt::RoundJoin));
     painter.drawLine(lastPoint, endPoint);
     modified = true;

     int rad = (myPenWidth / 2) + 2;
     update(QRect(lastPoint, endPoint).normalized()
                                      .adjusted(-rad, -rad, +rad, +rad));

褰撴湁澶氫釜signal榪炴帴鍒頒竴涓Ы鏃訛紝渚嬪鍦ㄤ繚瀛樻枃浠舵椂錛岀粰鍑虹殑QAction鏈?BMP JPG JPEG 絳夛紝姝ゆ椂鍙渶瑕佷竴涓猻ave錛堬級鐨勬Ы鍑芥暟錛宻ave錛堬級鍑芥暟闇瑕佺煡閬撴槸鍝釜signal鍙戦佽繃鏉ワ紝姝ゆ椂灝嗘牴鎹甉Object * QObject::sender () const   [protected]鏉ュ垽鏂璼ender
璇ュ嚱鏁頒粙緇嶅涓嬶細
QObject * QObject::sender () const   [protected]
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. The pointer is valid only during the execution of the slot that calls this function from this object's thread context.

The pointer returned by this function becomes invalid if the sender is destroyed, or if the slot is disconnected from the sender's signal.

Warning: This function violates the object-oriented principle of modularity. However, getting access to the sender might be useful when many signals are connected to a single slot.

Warning: As mentioned above, the return value of this function is not valid when the slot is called via a Qt::DirectConnection from a thread different from this object's thread. Do not use this function in this type of scenario.
鍏蜂綋scribble 閲屼唬鐮佸涓?br> void MainWindow::save()
 {
     QAction *action = qobject_cast<QAction *>(sender());
     QByteArray fileFormat = action->data().toByteArray();
     saveFile(fileFormat);
 }
絎竴鍙ワ細
QAction *action = qobject_cast<QAction *>(sender());
铏界劧涓嶇煡閬搒ender錛堬級鍏蜂綋鏄摢涓涓猀Action錛屼絾鎴戜滑鐭ラ亾鑲畾鏄竴涓猀Action錛屽洜姝ゅ彲浠ast榪囨潵銆?br>鐢╯tatic_cast<>涔熸槸鍙互鐨勶紝榪欓噷浣跨敤qobject_cast鐨勫師鍥犱緥瀛愰噷璇存槑濡備笅
but as a defensive programming technique we use a qobject_cast(). The advantage is that if the object has the wrong type, a null pointer is returned. Crashes due to null pointers are much easier to diagnose than crashes due to unsafe casts.
絎簩鍙ワ細
QAction閲屾湁setdata錛堬級 鍜?data錛堬級涓や釜鍑芥暟浣滅敤鏄繖鏍風殑
1.
QVariant QAction::data () const
Returns the user data as set in QAction::setData.
2.
void QAction::setData ( const QVariant & userData )
Sets the action's internal data to the given userData.

鍦ㄥ垱寤篞Action鐨勬椂鍊欙紝鎴戜滑setData錛堬級
     foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
         QString text = tr("%1...").arg(QString(format).toUpper());

         QAction *action = new QAction(text, this);
         action->setData(format);
         connect(action, SIGNAL(triggered()), this, SLOT(save()));
         saveAsActs.append(action);
     }
姝ゆ椂閫氳繃ction->data().toByteArray();鍙栧嚭鏉?br>鐒跺悗浼犵粰絎笁鍙ワ紝saveFile鍑芥暟灝辯煡閬撹瀛樹負鍝鏍煎紡浜?/p>

ps錛?br>鍦ㄧ晫闈㈢紪紼嬮噷錛屼緥濡傚啓涓涓猻ave錛堬級鍑芥暟錛屽彲鑳絪aveFile錛堬級鎵嶆槸瀹炵幇淇濆瓨鏂囦歡鐨勪綔鐢ㄧ殑銆?br>浣嗙偣鍑籹aveaction鏃訛紝璋冪敤save錛堬級錛屽疄闄呬笂闇瑕佸垽鏂悇縐嶆儏鍐碉紝渚嬪鏂囦歡鍚嶅悎娉?鍚屽悕絳夛紝闇瑕佹牴鎹笉鍚屾儏鍐靛脊鍑轟笉鍚岀殑瀵硅瘽妗嗭紝褰撳叏閮藉垽鏂璽rue鍚庯紝鎵嶄細璋冪敤saveFile錛堬級鍑芥暟錛岃繖鍙兘灝辨槸璺熶箣鍓嶈嚜宸辯紪紼嬪樊鍒瘮杈冨ぇ鐨勬儏鍐典簡锝烇綖



izualzhy 2011-03-18 21:33 鍙戣〃璇勮
]]>
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            中文国产一区| 亚洲专区欧美专区| 欧美国产激情二区三区| 久热综合在线亚洲精品| 免费观看在线综合色| 欧美国产亚洲精品久久久8v| 欧美大片一区二区三区| 欧美精品 日韩| 欧美性猛片xxxx免费看久爱| 国产精品手机在线| 一区精品在线| 一本色道久久综合一区| 午夜精品剧场| 亚洲二区免费| 亚洲日本va午夜在线影院| 日韩午夜在线电影| 亚洲一区二区三区免费观看| 蜜桃久久精品一区二区| 欧美www视频| 国产精品日本精品| 亚洲国产精品日韩| 亚洲欧美日韩天堂| 蜜臀av国产精品久久久久| 亚洲美女黄网| 久久9热精品视频| 欧美精品免费在线| 国产视频在线观看一区二区三区| 亚洲激情二区| 久久久一区二区| 一区二区三区高清视频在线观看| 久久精品国产亚洲高清剧情介绍| 欧美国产精品一区| 国产欧美日韩综合一区在线观看 | 国产精品高清网站| **性色生活片久久毛片| 亚洲一区二区视频| 欧美v日韩v国产v| 香蕉av福利精品导航| 欧美日韩在线影院| 91久久线看在观草草青青| 久久久精彩视频| 一区二区三区高清在线观看| 嫩草国产精品入口| 激情综合色综合久久综合| 欧美夜福利tv在线| 一区二区高清视频在线观看| 欧美成人精品影院| 亚洲国产视频直播| 欧美电影资源| 麻豆av福利av久久av| 精品福利av| 久久久久成人网| 午夜国产精品视频免费体验区| 欧美日韩你懂的| 中文欧美日韩| 亚洲精品一区二区网址| 欧美激情1区2区| 亚洲免费高清| 亚洲黄色免费| 欧美sm重口味系列视频在线观看| 怡红院精品视频| 欧美多人爱爱视频网站| 欧美+亚洲+精品+三区| 一区在线免费| 欧美多人爱爱视频网站| 欧美大尺度在线| 99国内精品久久久久久久软件| 亚洲二区免费| 欧美午夜精品电影| 欧美淫片网站| 久久九九热免费视频| 雨宫琴音一区二区在线| 欧美华人在线视频| 欧美日韩视频不卡| 久久精品91久久久久久再现| 久久国产66| 亚洲精品乱码视频| 99精品欧美一区| 国产亚洲欧美日韩美女| 欧美成年人网站| 欧美日韩高清在线一区| 亚洲一区二区三区高清| 午夜精品一区二区三区四区| 亚洲国产精品久久人人爱蜜臀| 免费欧美电影| 欧美日韩一区二区三| 久久精品国产久精国产一老狼| 久久天天躁狠狠躁夜夜爽蜜月| 91久久精品国产| 国产精品扒开腿做爽爽爽软件| 欧美网站在线| 久久精品系列| 欧美freesex交免费视频| 亚洲一区二区三区免费观看| 午夜精品久久久99热福利| 亚洲国产乱码最新视频| 一区二区三区精品视频在线观看| 国产精品制服诱惑| 欧美高潮视频| 国产精品美女久久福利网站| 麻豆精品一区二区综合av | 欧美日韩在线播放三区四区| 久久一区免费| 欧美香蕉大胸在线视频观看| 久久综合图片| 国产乱码精品一区二区三区五月婷 | 国内精品福利| 亚洲一区二区高清| 一区二区三区国产在线观看| 欧美专区日韩专区| 亚洲一区二区三区乱码aⅴ| 久久躁狠狠躁夜夜爽| 久久国产精品一区二区| 国产精品盗摄一区二区三区| 亚洲国产婷婷| 在线成人免费视频| 午夜视频一区二区| 亚洲综合色视频| 欧美精品性视频| 欧美大片一区| 亚洲电影中文字幕| 欧美怡红院视频| 亚洲欧美影院| 国产精品大全| 亚洲午夜电影网| 亚洲香蕉视频| 欧美日本精品| 亚洲精品一区二区在线观看| 亚洲精品小视频| 欧美激情国产精品| 欧美高清视频一区二区三区在线观看| 国产欧美日韩视频一区二区| 一本色道久久综合亚洲二区三区| 夜夜嗨av一区二区三区免费区| 麻豆精品91| 亚洲高清视频一区二区| 日韩视频中文字幕| 欧美精品成人91久久久久久久| 亚洲盗摄视频| 日韩亚洲国产精品| 欧美成人在线免费视频| 欧美成人xxx| 日韩视频久久| 欧美日韩国产bt| 99综合精品| 午夜精品久久久久久久99黑人| 国产精品视频免费一区| 亚洲欧美美女| 久久在线免费| 亚洲蜜桃精久久久久久久| 欧美日一区二区在线观看| 日韩午夜激情av| 美日韩精品视频| 在线观看免费视频综合| 久久午夜电影| 亚洲高清不卡在线| 在线视频欧美日韩精品| 国产精品男女猛烈高潮激情 | 欧美日韩国产成人在线| 亚洲一区二区3| 久久国产毛片| 最新高清无码专区| 国产精品电影网站| 久久成人国产| 亚洲精品乱码视频| 久久aⅴ国产紧身牛仔裤| 影音先锋中文字幕一区二区| 欧美精品在线观看| 午夜视频在线观看一区二区三区| 噜噜噜久久亚洲精品国产品小说| 日韩性生活视频| 国产精品视频大全| 久久久五月婷婷| 亚洲视频播放| 欧美激情一区二区三区在线视频 | 亚洲黄色影片| 国产精品一区二区久久| 欧美.com| 午夜精品视频在线观看一区二区| 欧美a级在线| 亚洲欧美日韩国产另类专区| 亚洲国产裸拍裸体视频在线观看乱了中文| 欧美日韩久久| 麻豆freexxxx性91精品| 亚洲欧美自拍偷拍| 99re66热这里只有精品4| 久久免费视频在线观看| 亚洲午夜视频在线| 亚洲激情在线激情| 黄色亚洲精品| 国产欧美在线观看| 欧美日韩黄色大片| 免费看亚洲片| 久久婷婷人人澡人人喊人人爽 | 欧美精品亚洲一区二区在线播放| 久久国产精品一区二区三区| 亚洲一区二区三区免费在线观看| 亚洲激情视频在线观看| 免费国产一区二区| 久久精品人人做人人综合|