QML 输入框的一些问题



  • 0_1523974188470_c1c7dd85-f326-4806-9c58-002d167c83b4-undefined

    如图所示,QML所有输入控件都会有的一个问题,想屏蔽系统自带的大光标样式,而采用自定义的光标样式
    0_1523974286223_149e8668-8073-4842-adc2-d08808a3acc3-undefined



  • @lowbees 试一试:

    SpinBox
    {
        contentItem.selectByMouse: false
    }
    


  • @jiangcaiyang 这个属性默认就是false的



  • 是不是可以activeFocusOnPress:false或者selectByMouse: false。selectByMouse默认是true



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



  • @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 赶紧看一看它的精髓,估计就是什么设置导致可以使用默认的选择光标样式。


 

最近的回复

  • 0_1539655233041_329385492.jpg
    各位大家好哦。
    经过一个晚上对论坛的维护更新,我们成功地将论坛更新到最新的版本。这次的版本更新主要是提升了稳定性,因此功能上和原来的一样,请大家放心,不会出现奇怪的东西什么的啦。然后呢,由于提升了稳定性,因此论坛不会莫名其妙地出现未响应的情况,总之比以前好就对啦。

    此外,论坛新增了自己研制的一个分享的插件:nodebb-plugin-share-sns-cn。这个插件呢,主要是做主流社交网站的分享的。目前暂时支持QQ、微博以及微信的分享。目前初版是1.0。

    希望大家常常来论坛玩~

    阅读更多
  • 发一些二次元妹子图吧。谁叫我有时候也挺无聊的呢~
    0_1539486167719_119.jpg

    阅读更多
  • 0_1539445819168_123.jpg
    各位大家好!
    又有一段时间啦。我们的萌梦动作编辑器又进行更新啦!☺ ☺
    这次的更新呢,主要是完善了一下自动构建系统。也就是说为了持续构建并且能够给到爱好者可用并且稳定的软件,我们做了很多的努力,其中一点就是制作了脚本进行持续构建,以前要花很多很多的时间对动作编辑器进行构建,现在呢,没有那么复杂了。简简单单地数个批处理操作,即可快速构建咱们的动作编辑器,使得从代码到产品只需要十几分钟即可完成,比以前的速度节省了90%的时间,可谓神速!这套系统已经成功地应用到Windows平台线上了,现在基本可以做到每日构建的水平。而且为每次构建专门准备了pdb文件,即一旦用户运行动作编辑器出现了问题,可以通过程序调试数据库定位到问题的位置,从而提升服务的水平,想想这对于我一直坚持的萌梦这款产品来说算是革命性的操作呢。

    当然现在这套系统只能应用在Windows线上,Mac OS X这条线是我接下来努力的方向,也希望能够实现Mac这条线的每日构建效果。然后Linux平台也比较重要,想起Linux开发应该比Windows等等要方便,所以我想难度比Windows的要小很多,甚至比Mac OS X的都要小。总之路途还很遥远,加油努力吧!

    这次的Windows版本已经成功地在Windows的安装包中进行测试,同时提供在线的和离线的安装包。下面就是这些安装包的github下载地址。

    Windows在线安装包
    Windows离线安装包

    阅读更多
  • 手动给一个赞!!☺ 🤗
    0_1539264026793_好美的图啊.jpg

    阅读更多

关注我们

微博
QQ群











召唤伊斯特瓦尔