【问题标题】:How to set the color of caret blinking cursor in QLineEdit如何在 QLineEdit 中设置插入符号闪烁光标的颜色
【发布时间】:2021-08-13 08:56:35
【问题描述】:

如何在 QLineEdit 中设置插入符号闪烁光标的颜色? 我有一个问题,就是如何改变QLineEdit中插入符号闪烁光标的颜色。

【问题讨论】:

    标签: qt cursor qt5 qlineedit


    【解决方案1】:

    您可以尝试一种方法。 理论上它看起来应该可以工作(未经测试。寻找编译时错误。)

    首先获取要设置的图标的图像。 然后加载图片得到QPixmap对象。

    QPixmap myPixmap;
    myPixmap.load("<<YOURIMAGEPATH>>/cursoricon.png");
    

    现在将颜色设置为 QPixmap 使用 https://doc.qt.io/qt-5/qpixmap.html#fill

    myPixmap.fill(QColor(0,255,0));
    

    现在使用QPixmap 对象创建一个QCursor 对象 https://doc.qt.io/qt-5/qcursor.html#QCursor-3

    QCursor cursor = QCursor(myPixmap);
    

    然后将光标设置到您的行编辑对象。

    pLineEdit->setCursor(cursor);
    

    其实是setCursor函数,一开始我以为它只对鼠标光标有效。 但是文档说它也适用于编辑器小部件。 https://doc.qt.io/qt-5/qwidget.html#cursor-prop

    编辑器小部件可能使用 I 型光标

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-30
      • 2022-09-27
      • 2019-09-17
      • 2019-10-01
      • 1970-01-01
      • 2011-06-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多