Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. <SOLVED> Text editor found text is not visible.
Forum Updated to NodeBB v4.3 + New Features

<SOLVED> Text editor found text is not visible.

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 3.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    haney
    wrote on last edited by
    #1

    Hi,

    I have a text editor and used the same find()method of QTextEdit. But when a word is found the first occurrence of it is selected and not visible. Please copy and try the code from below and search for hello word in texteditor.

    code:
    @
    //main.cpp file

    #include "myApplication.h"

    int main(int argc, char **argv)
    {
    MyApplication app(argc, argv);

    return app.exec();
    }
    @

    @
    //myApplication.h File

    #ifndef MYAPPLICATION_H
    #define MYAPPLICATION_H

    #include <QtGui>

    //Derived Class from QApplication
    class MyApplication: public QApplication
    {
    Q_OBJECT
    public:
    MyApplication(int & argc, char ** argv ):QApplication(argc,argv)
    {

    QMainWindow *window = new QMainWindow();

    window->setWindowTitle(QString::fromUtf8("QTextEdit Highlight Comment Text"));
    window->resize(300, 250);

    QWidget *centralWidget = new QWidget(window);

    QVBoxLayout* layout = new QVBoxLayout(centralWidget);

    edit = new QTextEdit();

    layout->addWidget(edit);

    button = new QPushButton("Find");
    lineEdit = new QLineEdit();
    layout->addWidget(lineEdit);
    layout->addWidget(button);

    window->setCentralWidget(centralWidget);

    connect(button,SIGNAL(clicked()),this,SLOT(findText()));
    window->show();

    };
    ~ MyApplication(){};

    public slots:
    void findText()
    {
    //Set Cursor position to the start of document
    //to let find() method make search in whole text.
    //Otherwise it will make search from cursor position to the end.
    edit->moveCursor(QTextCursor::Start);
    edit->find(lineEdit->text());
    };

    public:
    QTextEdit* edit;
    QPushButton* button;
    QLineEdit* lineEdit;

    };
    #endif @

    http://www.codeprogress.com/cpp/libraries/qt/QTextEditFindHighlightExample.php

    Plz help me regarding this issue. I am working on open SuSe 12.1 is that the problem, suggest ur views.

    Thanks

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      Is the color of the selected text set to white like the background?

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • H Offline
        H Offline
        haney
        wrote on last edited by
        #3

        No.. I did not set any background color.. Plz try the example given in link and type some text in editor and then click find button.. I want to know if this behavior is only with SuSe or other OS also..

        Thanks,,,

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          On windows i can see the text slightly.

          in your main function add :
          @app.setStyleSheet("QTextEdit {selection-background-color: darkblue; selection-color: yellow; }");@

          and you should see the text highlighted.

          This proves my initial guess that the selected text color is the same as the background. It's a common error not easy to detect. I think we all have to deal with this sooner or later ;)

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stevenceuppens
            wrote on last edited by
            #5

            Tried both versions on Mac,

            Haney, in your code the first occurrence is selected in light gray, its slightly visible on MAC.

            The stylesheet adaption of Eddy makes it much more clear! :)

            My guess is that Eddy's guess was a good guess! ;)

            Steven CEUPPENS
            Developer &#x2F; Architect
            Mobile: +32 479 65 93 10

            1 Reply Last reply
            0
            • EddyE Offline
              EddyE Offline
              Eddy
              wrote on last edited by
              #6

              Hi Steven,

              Welcome to devnet!

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • H Offline
                H Offline
                haney
                wrote on last edited by
                #7

                Thanks very much Eddy...

                setting stylesheet fixed my problem..

                1 Reply Last reply
                0
                • EddyE Offline
                  EddyE Offline
                  Eddy
                  wrote on last edited by
                  #8

                  You're welcome.

                  Have fun.

                  Qt Certified Specialist
                  www.edalsolutions.be

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved