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. Problems subclassing QTextEdit in a custom widget.
Forum Updated to NodeBB v4.3 + New Features

Problems subclassing QTextEdit in a custom widget.

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 2 Posters 742 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.
  • J Offline
    J Offline
    JoeJoe_000
    wrote on last edited by JoeJoe_000
    #1
    This post is deleted!
    1 Reply Last reply
    0
    • J Offline
      J Offline
      JoeJoe_000
      wrote on last edited by
      #11

      I believe the work around is to not override contextMenuEvent in the QTextEdit box this gives me the Context Menu of the QWidget and then just add all my items to the Widget contextMenuEvent.

      mrjjM 1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi
        so you have a custom QTextEdit inside a custom QWidget ?
        And if you click on the QTextEdit, you have added code so it setFocus on its parent the custom QWidget ?

        Im not sure i understand why you do that `?

        J 1 Reply Last reply
        0
        • J Offline
          J Offline
          JoeJoe_000
          wrote on last edited by
          #3

          Hello MrJJ, the reason why is my external Widget has an indicator that displays a highlighted box when it's being used. I would like it to indicate a color when the text box has been clicked.

          mrjjM 1 Reply Last reply
          0
          • J JoeJoe_000

            Hello MrJJ, the reason why is my external Widget has an indicator that displays a highlighted box when it's being used. I would like it to indicate a color when the text box has been clicked.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @JoeJoe_000
            Hi
            But why do you need to take focus back to the custom widget ?
            Could your textEdit not just emit a signal to tell the parent to show
            the indicator and if the user moves out of the Textedit again ( leaveEvent) then send signal
            to hide the indicator again. ?

            Or do i still not get it ? :)

            1 Reply Last reply
            0
            • mrjjM mrjj

              Hi
              so you have a custom QTextEdit inside a custom QWidget ?
              And if you click on the QTextEdit, you have added code so it setFocus on its parent the custom QWidget ?

              Im not sure i understand why you do that `?

              J Offline
              J Offline
              JoeJoe_000
              wrote on last edited by
              #5
              This post is deleted!
              mrjjM 1 Reply Last reply
              0
              • J Offline
                J Offline
                JoeJoe_000
                wrote on last edited by
                #6

                I will do as you suggested. Thanks.

                1 Reply Last reply
                0
                • J JoeJoe_000

                  This post is deleted!

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @JoeJoe_000
                  Ah so to get the handles, you need to tell the Container it has focus ?

                  J 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @JoeJoe_000
                    Ah so to get the handles, you need to tell the Container it has focus ?

                    J Offline
                    J Offline
                    JoeJoe_000
                    wrote on last edited by JoeJoe_000
                    #8

                    @mrjj said in Problems subclassing QTextEdit in a custom widget.:

                    he handles, you need to tell the Container it has focus ?

                    So when you utilize the Resizeable widget the user will click on it as a result focus is obtained that is communicated with the indicator. This all done via

                    bool TContainer::eventFilter(QObject *obj, QEvent *evt) {
                    if (m_infocus) {
                    QWidget *w = this->parentWidget();
                    if (w == obj && evt->type() == QEvent::Paint) {
                    // Draw container selection
                    QPainter painter(w);
                    QPoint p = this->mapTo(w, QPoint(-3, -3));
                    QPoint LT = w->mapFrom(w, p);
                    QPoint LB = w->mapFrom(w, QPoint(p.x(), p.y() + this->height()));
                    QPoint RB = w->mapFrom(w, QPoint(p.x() + this->width(), p.y() + this->height()));
                    QPoint RT = w->mapFrom(w, QPoint(p.x() + this->width(), p.y()));

                            painter.fillRect(LT.x(), LT.y(), 6, 6, QColor("black"));
                            painter.fillRect(LB.x(), LB.y(), 6, 6, QColor("black"));
                            painter.fillRect(RB.x(), RB.y(), 6, 6, QColor("black"));
                            painter.fillRect(RT.x(), RT.y(), 6, 6, QColor("black"));
                            return QWidget::eventFilter(obj, evt);
                        }
                    }
                    return QWidget::eventFilter(obj, evt);
                    

                    }

                    The painter.fillRect lines will display the four boxes.

                    I've subclassed this object and created a custom object of my own. I've reimplemented the mousePressEvent and thus call The TContainer event from there.

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      JoeJoe_000
                      wrote on last edited by
                      #9

                      to clear things up the focusIn event calls the paint event thus the eventFilter intercepts the event and paints the indicators.

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        JoeJoe_000
                        wrote on last edited by
                        #10

                        I should also mention I'm utilizeing contextMenuEvent(QContextMenuEvent *e) in my QTextEdit obj.

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          JoeJoe_000
                          wrote on last edited by
                          #11

                          I believe the work around is to not override contextMenuEvent in the QTextEdit box this gives me the Context Menu of the QWidget and then just add all my items to the Widget contextMenuEvent.

                          mrjjM 1 Reply Last reply
                          0
                          • J JoeJoe_000

                            I believe the work around is to not override contextMenuEvent in the QTextEdit box this gives me the Context Menu of the QWidget and then just add all my items to the Widget contextMenuEvent.

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #12

                            @JoeJoe_000
                            That sounds like an ok fix.
                            I dont know TContainer very well but i recall it was somewhat complex but working good.

                            1 Reply Last reply
                            0
                            • J Offline
                              J Offline
                              JoeJoe_000
                              wrote on last edited by
                              #13

                              It's definitely the class to use to get better at learning Qt. Thanks for your help bro! Oh, and by the way I was looking at your profile I see you made a game called Thug Life, what did you use to make that?

                              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