QML 输入框的一些问题



  • 我记得是可以自定义光标样式的



  • @linbin823 @青山白云 真正想要的是能自定义这个鼠标(pc的说法)样式, 0_1524020326995_676b9a70-65a0-4b36-84f4-e4b2ae2f996e-undefined 类似于这种效果



  • @lowbees 我记得哪里看到过源代码,可以进行处理的。稍等一下,我查找一下。



  • 那我猜你不能直接用controls这种现成的控件了,得深度定制。



  • @linbin823 具体在这里:
    G:\qt-everywhere-src-5.10.0\qtbase\src\android\jar\src\org\qtproject\qt5\android
    可能的方式就是

    1、先读懂代码的内容
    2、尝试用Java编译这部分的jar包
    3、再替换掉你编译的Qt程序中的相应部分

    顺便看看是否有机会可以通过继承的方式替换。你再看一看。
    附:CursorHandle.java文件

    /****************************************************************************
    **
    ** Copyright (C) 2016 Olivier Goffart <ogoffart@woboq.com>
    ** Contact: http://www.qt.io/licensing/
    **
    ** This file is part of the Android port of the Qt Toolkit.
    **
    ** $QT_BEGIN_LICENSE:LGPL$
    ** Commercial License Usage
    ** Licensees holding valid commercial Qt licenses may use this file in
    ** accordance with the commercial license agreement provided with the
    ** Software or, alternatively, in accordance with the terms contained in
    ** a written agreement between you and The Qt Company. For licensing terms
    ** and conditions see https://www.qt.io/terms-conditions. For further
    ** information use the contact form at https://www.qt.io/contact-us.
    **
    ** GNU Lesser General Public License Usage
    ** Alternatively, this file may be used under the terms of the GNU Lesser
    ** General Public License version 3 as published by the Free Software
    ** Foundation and appearing in the file LICENSE.LGPL3 included in the
    ** packaging of this file. Please review the following information to
    ** ensure the GNU Lesser General Public License version 3 requirements
    ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
    **
    ** GNU General Public License Usage
    ** Alternatively, this file may be used under the terms of the GNU
    ** General Public License version 2.0 or (at your option) the GNU General
    ** Public license version 3 or any later version approved by the KDE Free
    ** Qt Foundation. The licenses are as published by the Free Software
    ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
    ** included in the packaging of this file. Please review the following
    ** information to ensure the GNU General Public License requirements will
    ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
    ** https://www.gnu.org/licenses/gpl-3.0.html.
    **
    ** $QT_END_LICENSE$
    **
    ****************************************************************************/
    
    package org.qtproject.qt5.android;
    
    import android.content.Context;
    import android.os.Bundle;
    import android.util.DisplayMetrics;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.widget.LinearLayout;
    import android.widget.ImageView;
    import android.content.res.TypedArray;
    import android.graphics.drawable.Drawable;
    import android.view.MotionEvent;
    import android.widget.PopupWindow;
    import android.app.Activity;
    import android.view.ViewTreeObserver;
    
    /* This view represents one of the handle (selection or cursor handle) */
    class CursorView extends ImageView
    {
        private CursorHandle mHandle;
        // The coordinare which where clicked
        private int m_offsetX;
        private int m_offsetY;
    
        CursorView (Context context, CursorHandle handle) {
            super(context);
            mHandle = handle;
        }
    
        // Called when the handle was moved programatically , with the delta amount in pixels
        public void adjusted(int dx, int dy) {
            m_offsetX += dx;
            m_offsetY += dy;
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            switch (ev.getActionMasked()) {
            case MotionEvent.ACTION_DOWN: {
                m_offsetX = Math.round(ev.getRawX());
                m_offsetY = Math.round(ev.getRawY());
                break;
            }
    
            case MotionEvent.ACTION_MOVE: {
                mHandle.updatePosition(Math.round(ev.getRawX()) - m_offsetX,
                                        Math.round(ev.getRawY()) - m_offsetY);
                break;
            }
    
            case MotionEvent.ACTION_UP:
                break;
    
            case MotionEvent.ACTION_CANCEL:
                break;
            }
            return true;
        }
    
    }
    
    // Helper class that manages a cursor or selection handle
    public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
    {
        private View m_layout = null;
        private CursorView m_cursorView = null;
        private PopupWindow m_popup = null;
        private int m_id;
        private int m_attr;
        private Activity m_activity;
        private int m_posX = 0;
        private int m_posY = 0;
        private int m_lastX;
        private int m_lastY;
        int tolerance;
        private boolean m_rtl;
    
        public CursorHandle(Activity activity, View layout, int id, int attr, boolean rtl) {
            m_activity = activity;
            m_id = id;
            m_attr = attr;
            m_layout = layout;
            DisplayMetrics metrics = new DisplayMetrics();
            activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
            tolerance = Math.round(2 * metrics.density);
            m_lastX = m_lastY = -1 - tolerance;
            m_rtl = rtl;
        }
    
        private boolean initOverlay(){
            if (m_popup == null){
    
                Context context = m_layout.getContext();
                int[] attrs = {m_attr};
                TypedArray a = context.getTheme().obtainStyledAttributes(attrs);
                Drawable drawable = a.getDrawable(0);
    
                m_cursorView = new CursorView(context, this);
                m_cursorView.setImageDrawable(drawable);
                // m_layout.addView(m_cursorView);
    
                m_popup = new PopupWindow(context, null, android.R.attr.textSelectHandleWindowStyle);
                m_popup.setSplitTouchEnabled(true);
                m_popup.setClippingEnabled(false);
                m_popup.setContentView(m_cursorView);
                m_popup.setWidth(drawable.getIntrinsicWidth());
                m_popup.setHeight(drawable.getIntrinsicHeight());
    
                m_layout.getViewTreeObserver().addOnPreDrawListener(this);
            }
            return true;
        }
    
        // Show the handle at a given position (or move it if it is already shown)
        public void setPosition(final int x, final int y){
            initOverlay();
    
            final int[] location = new int[2];
            m_layout.getLocationOnScreen(location);
    
            int x2 = x + location[0];
            int y2 = y + location[1];
    
            if (m_id == QtNative.IdCursorHandle) {
                x2 -= m_cursorView.getWidth() / 2 ;
            } else if ((m_id == QtNative.IdLeftHandle && !m_rtl) || (m_id == QtNative.IdRightHandle && m_rtl)) {
                x2 -= m_cursorView.getWidth() * 3 / 4;
            } else {
                x2 -= m_cursorView.getWidth() / 4;
            }
    
            if (m_popup.isShowing()) {
                m_popup.update(x2, y2, -1, -1);
                m_cursorView.adjusted(x - m_posX, y - m_posY);
            } else {
                m_popup.showAtLocation(m_layout, 0, x2, y2);
            }
    
            m_posX = x;
            m_posY = y;
        }
    
        public void hide() {
            if (m_popup != null) {
                m_popup.dismiss();
            }
        }
    
        // The handle was dragged by a given relative position
        public void updatePosition(int x, int y) {
            if (Math.abs(m_lastX - x) > tolerance || Math.abs(m_lastY - y) > tolerance) {
                QtNative.handleLocationChanged(m_id, x + m_posX, y + m_posY);
                m_lastX = x;
                m_lastY = y;
            }
        }
    
        @Override
        public boolean onPreDraw() {
            // This hook is called when the view location is changed
            // For example if the keyboard appears.
            // Adjust the position of the handle accordingly
            if (m_popup != null && m_popup.isShowing())
                setPosition(m_posX, m_posY);
    
            return true;
        }
    }
    


  • @jiangcaiyangQML 输入框的一些问题 中说:

    is part of the Android port of the Qt Toolkit.

    这么说是要重新编译qt?





  • @lowbees 不清楚,我只是看到有这样的源码了,具体怎么玩转,希望你再看一下,是否可以做到不修改源代码即可个性化输入光标。



  • @jiangcaiyang 😆 还是得等官方或者大佬解决了



  • 0_1524313514973_1b13449a-d1bf-4398-80ae-1fc61bcb5698-undefined 突然在官方给出showroom看到一个东西 https://showroom.qt.io/qml-creator/



  • 找到了github的地址 https://github.com/olegyadrov/qmlcreator
    ,具体位置在这里:qmlcreator/qml/components/CCodeArea.qml



  • @lowbees 赶紧看一看它的精髓,估计就是什么设置导致可以使用默认的选择光标样式。


 

最近的回复

关注我们

微博
QQ群











召唤伊斯特瓦尔
mar"fa >mar"i cod1pI Dispfalse,"}dindownvar"i cod1pI Dispfalse,"}diranstposttagookmstonlir":"2Pi cod1pItagoC:"linb1}dilo e In":ls":diranslate_path.85etutempnsl"nvar":6,"pa
* r pl1vij> 这员慢跑社区ttion/\ clas\r /ve_ico_ite\4iv> _br/>_br/>_br/>_br/>_br/>_br/>_br/>_br/>_br/>_hr p\r
\rr/> :5px;bottom:0px;\ p\n /ve_ico_ite\4mze( "e\tatu_val\"opaeft::0r pv\/clas\n /canvasuqil\"lcaiho\tawp.sel\"500nt":cu l\"5604020326995_lcaiho\tpv\/canvasp\n /ve_ico_ite\4eButt"sho_g/med_uody\ p\n \t/ve_ico_ite\4eButt"sho_g/med_":6,_uody\ p\n \t/media/outer\r":6,\ 4020326995_lcait"sho_} ); w <_g/med\"uqil\" ); e/uputoi cl这l\"offe/upnsceLICEerl\"甚名字 p\ /\ clas\ /ve_ico_ite\4eButt"sho_g/med_iv> _uody\ p\n \t/media/outer\r"sho\ 4020326995_lcait"sho_"sho w <_g/med\"uqil\" ); Tv> 402putoi cl这l\"offe/upnsceLICEerl\"要咋到聊"AIuse呀? p\ /button <2ae2f\n /ve_ico_ite\4eButtico_uox\ p\n \t/ve_ico_ite\4eButtico_ <2ae2f\n /ludio能\tatu_val\"splay_m:none;\"uqil\"lcai2d_bgr li> bg7\"0\ pre-wei":fjine\"pntioudios\n /media/outer\rlcai2dBGM\"uid=787\" Oliviemusic.163-mentsong/media/ou
<2as\n /media/outer\rlcai2dBGM\"uid=787\" Oliviemusic.163-mentsong/media/ou
<2as\n /media/qil\"duext(\"uid=787\"douqilai,l2d_serhong\ <2as\n v\/clas\nv\/clas\nv"douqil\"i,l2dlcaiho\tp召唤伊斯特瓦尔v\/clas\nvfa-fast\n'/wwwstMett';\nvar onLwei = fun }\n( ceeak;\n n** inf( [ \rlcai2DMze( "e\ta], fun }\n ( lcai2DMze( "e ) eak;\n lcai2DMze( "e.lce;ializf( \"e506e0f34db84e518d37abb4840b6c59\ta lcai2DMze( "e.onLwei(a }a $( \"# ); e/u) ( \"id=78\", are.; .ndex":6,a m_lal;\nawpupWi.jQuery ceeak;\n onLwei(a aer.useeak;\n wpupWi.adrent.AtextS$ro '-wei', onLwei a\nv\/fa-fastef]ros fubar/Pid"pl-2lay_ve_ico_ite\4ileel ui- } chev-.ViewTrileel-primary\ p_ve_ico_ite\4ileel-hearset\ p_div> r av> r-sm ji/emoji/emoji\tat能 fa-weixig","repu49ation":102,"jp.r /p\r \t\t\r \t/tion\r \r \t/pp\r \t\t/lass="f\tl
应用启动时加载缓存数据/tion\r \t用cor \tfile20326995_pull-******Sime-p.GPL3\-r/> r av> r-sm ji/emoji/emoji\tat能 fa-weixig","repu5ation":102,"posr /p\r \t\t\r \t/tion\r \r \t/pp\r \t\t/lass="f\tl 中/tion\r \t用cor \tfile20326995_pull-******Sime-p.GPL3\-r/> r av> r-sm ji/emoji/emoji\tatu_val\"backgDispl-se:nu: #3f51b5;\ pM/\ clas\r \t\t\r \t/tion\r \r \t/pp\r \t\t/lass="f\tl Lweier 属性传递:false-中on\r \t用cor \tfile20326995_pull-******Sime-p.GPL3\-r/> r av> r-sm ji/emoji/emoji\tatu_val\"backgDispl-se:nu: #33691e;\">C/\ clas\r \t\t\r \t/tion\r \r \t/pp\r \t\t/lass="f\tl MotedA . 重叠看怎实,{"c动看点击 class/tion\r \t用cor \tfile20326995_pull-******Sime-p.GPL3\-r/> r av> r-sm ji/emoji/emoji\tat能 fa-weixig","repu49ation":102,"jp.r /p\r \t\t\r \t/tion\r \r \t/pp\r \t\t/lass="f\tl r av> r-sm ji/emoji/emoji\tat能 fa-weixig","repu5ation":102,"posr /p\r \t\t\r \t/tion\r \r \t/pp\r \t\t/lass="f\tl 底层实,{"之 te>\Sa-fas 变量编码/tion\r \t用cor \tfile20326995_pull-******Sime-p.GPL3\-r/> r av> r-sm ji/emoji/emoji\tat能 fa-weixig","repu5ation":102,"posr /p\r \t\t\r \t/tion\r \r \t/pp\r \t\t/lass="f\tl 分数据库看能皨 c++ 打开-中on\r \t用cor \tfile20326995_pull-******Sime-p.GPL3\-r/> r av> r-sm ji/emoji/emoji\tat能 fa-weixig","repu49ation":102,"jp.r /p\r \t\t\r \t/tion\r \r \t/pp\r \t\t/lass="f\tl An\n t":" numderasl\"4r li> cqil\"r p\r \t\r /li2i> pqil\"61074020326995_dlearfix wable;-derasr p\r \t/lass="f\tlted"/in-m白云r p\r \r \t\t\r \t\tvve_iull-ri\fin-m白云r 20326995_av> r av> r-sm ji/emoji/emoji\tatu_val\"backgDispl-se:nu: #groupT;\">i/\ clas\r \t\t\r \t/tion\r \tvve_p\r \t\t/move_tools":false,"display_post_menu":true},{"content":"

\n3、\r \t\t/m20326995_dide-oed\">用cor \t\ clas\r \tfile20326995_pull-******Sime-p.GPL3\-r/>阅 />\3:38.on\r \tfilep\r /\ lin\r \r /li2i> pqil\"61064020326995_dlearfix wable;-derasr p\r \t/lass="f\tlted"/"},"user":{"r p\r \r \t\t\r \t\tvull-ri\f"},"user":{"r 20326995_av> r av> r-sm ji/emoji/emoji\tat能 fa-weixig","reputation":102,"posr /p\r \t\t\r \t/tion\r \tvve_p\r \t\t/move_tools":false,"display_post_menu":true},{"content":"

\n3、\r \t\t/m20326995_dide-oed\">用cor \t\ clas\r \tfile20326995_pull-******Sime-p.GPL3\-r/>阅 />\3:38.on\r \tfilep\r /\ lin\r \r /li2i> pqil\"61054020326995_dlearfix wable;-derasr p\r \t/lass="f\tlted"/darongyir p\r \r \t\t\r \t\tvull-ri\fdarongyir 20326995_av> r av> r-sm ji/emoji/emoji\tat能 fa-weixig","reput67ation":102,"jp.r /p\r \t\t\r \t/tion\r \tvve_p\r \t\t/moI Lessetest wpupWithe GNU .. Hope MACthe GNU Gi ces soU G!s的n1542509能自定义ng article. I visit frequently. 用cor \t\ clas\r \tfile20326995_pull-******Sime-p.GPL3\-r/>阅 />\3:38.on\r \tfilep\r /\ lin\r \r /li2i> pqil\"61044020326995_dlearfix wable;-derasr p\r \t/lass="f\tlted"/darongyir p\r \r \t\t\r \t\tvull-ri\fdarongyir 20326995_av> r av> r-sm ji/emoji/emoji\tat能 fa-weixig","reput67ation":102,"jp.r /p\r \t\t\r \t/tion\r \tvve_p\r \t\t/moi 用cor \t\ clas\r \tfile20326995_pull-******Sime-p.GPL3\-r/>阅 />\3:38.on\r \tfilep\r /\ lin\r \r \tuls\r /\ clas\r \r /fa-fast\r\n'/wwwstMett';\rid.apglobals are, sockee(0)ransl_too(0)empnsl"s*/\r (fun }\n(ceear \tfun }\n onLwei(ceear \t\tvar ll,"boo = $('#rostsWoderas'ut;r ar \t\tare. .peU Tooltipyout;r \t\ttiocessHl-2(ll,"boout;r ar \t\tvar llstsWtextsWable;inStre.wable;o.llstsWtexts;ar \t\tvar numtextsinSpts[0Int(ll,"boo ('i> numderas'), 10var n4t;r ar \t\tl;\n!llstsWtextsWable;ceear \t\t\tllstsWtextsWable;inS{};ar \t\t\tllstsWtextsWable;.onNewtext = fun }\n(i> ceear \r \t\t\t\tvar cooleall,"boo ('i> coo');\r \t\t\t\tvar llstsWtexts = $('#rostsWoderas'ut;r at\t\t\tl;\n!llstsWtexts.lengthceear \t\t\t\t\tll< int;r at\t\t\t}ar \r \t\t\t\tl;\ncool&&Spts[0Int(coo, 10va!=nSpts[0Int(i> .deras[0]. .deras;r at\t\t\t}, fun }\n(pl-2ceear \t\t\t\t\ttiocessHl-2(pl-2c;ar \r \t\t\t\t\tpl-2., func\r \t\t\t\t\t\t.p.GpendTo(llstsWtextsc\r \t\t\t\t\t\t.dideIn(c;ar \r \t\t\t\t\tare. .peU Tooltipyout;r \t\t\t\t\tl;\nllstsWtexts.children(c.length > numtextsceear \t\t\t\t\t\tllstsWtexts.children(c.last(c.rete_tout;r \t\t\t\t\t};r at\t\t\t}ut;r \t\t\t};ar \r \t\t\ttre.wable;o.llstsWtextsleallstsWtextsWable;t;r \t\t\tsockee.on('ent.A:newodera', are.wable;o.llstsWtexts.onNewtextut;r \t\t}ar \r \t\tfun }\n tiocessHl-2(pl-2ceear \t\t\tare.ll,"-onSelfLinks(pl-2.fpup('a')c;ar \r \t\t\tpl-2.fpup(':ji/(.ji/emoji/emoji)'$roiCools('emoji/emoji'ut;r at\t\tpl-2.fpup('file.-18Tago'$-18Tago(ut;r \t\t}ar \t}ar \r \r \tl;\nwpupWi.jQueryceear \t\tonLwei(ct;r \taer.useear \t\twpupWi.adrent.AtextS$ro'-wei', onLweict;r \ta;r })(ct;r /\ fa-fast\r\n/\ clasv\ clasaf]}}< fa-fast < clasv!-- /.div compo#e,"disp --> < mcom> /fa-fas def_me能"/olse;ot frequ.min.jscom/plugins/no"pn fa-fast /fa-fas def_me /式fa-fas"e能"/olse;ot/bilibili.js"pn fa-fast /fa-fas def_me /式fa-fas"e能"/olse;otnt.dor/jquery/-18Tago/loiv> /fa-fast wpupWi.adrent.AtextS$ro'-wei', fun }\n (cee \"0_15( fig.llnslate_path + '/olse;ot)empnsl"s/500.js', fun }\n (cee fun }\n i cl":1d(helpe G, in, gee(0i内部错误n ftrong>\ \t/pp哎呀!看来中里出错>那