Problems subclassing QTextEdit in a custom widget.
-
This post is deleted!
-
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.
-
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 `?
-
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.
-
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.
@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 ? :)
-
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 `?
This post is deleted! -
I will do as you suggested. Thanks.
-
This post is deleted!
@JoeJoe_000
Ah so to get the handles, you need to tell the Container it has focus ? -
@JoeJoe_000
Ah so to get the handles, you need to tell the Container it has focus ?@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.
-
to clear things up the focusIn event calls the paint event thus the eventFilter intercepts the event and paints the indicators.
-
I should also mention I'm utilizeing contextMenuEvent(QContextMenuEvent *e) in my QTextEdit obj.
-
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.
-
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.
@JoeJoe_000
That sounds like an ok fix.
I dont know TContainer very well but i recall it was somewhat complex but working good. -
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?