Hi
I've got a quick question in regard with the Mdi Area in Qt. Is it possible to add normal text on the background? I've checked the MdiArea and QBrush documentation and it does not seem possible.
Have anyone done this before?
Thanks
Jaco
Hi
I've got a quick question in regard with the Mdi Area in Qt. Is it possible to add normal text on the background? I've checked the MdiArea and QBrush documentation and it does not seem possible.
Have anyone done this before?
Thanks
Jaco
Open a painter on the viewport (either by providing your own or through an event filter) and paint the text you want using it.
Thanks again for the reply Wysota.
I've tried your suggestions, and I think I'm missing something small somewhere. I've re-implemented the paint event of the mdiArea using an event filter. However, the mdiArea still shows up blank (white background). I tried to use the example in the Qt documentation as shown below:
Qt Code:
loggerSingleton::Instance()->addDebugString("Found paint event for mdiArea...",0); painter.setPen(Qt::blue); painter.drawText(paintEvent->rect(), Qt::AlignCenter, "Test 123..."); return true;To copy to clipboard, switch view to plain text mode
Should I link my painter with the paint event somehow?
Also, do you know of a good place to start learning the details of viewports? I've searched the Qt docs, but none of them explain the viewport specifically, unless I missed it...
Thanks
Jaco
Where are you writing the above code ?
you could create a painter on viewport as -
QPainter painter(myMdiArea->viewport());
Hope am right![]()
The above code is in an event filter for the mdiArea. I'm sure the event filter is working, so the problem somewhere else.
I've constructed the QPaintDevice using the QPainter constructor as you said, but still its not working...
Qt Code:
loggerSingleton::Instance()->addDebugString("Found paint event for mdiArea...",0); this->updateMessagesAndLogs(); //QPaintEvent *paintEvent = static_cast<QPaintEvent*>(event); painter.setPen(Qt::blue); painter.drawText(10,10, "Test 123..."); return true;To copy to clipboard, switch view to plain text mode
as far as I know this should work since the constructor calls begin() for you automatically. However when I launch the application and the paint event is called twice, the first time it steps through the code above without any problems, but the second time it give the following warnings:
Qt Code:
To copy to clipboard, switch view to plain text mode
I take it that the mdi area installs an event filter on the viewport itself and it causes some interference with your event filter. I suggest taking a look into QMdiArea's source code to see what it does and do the same.
Is your code inside QWidget::paintEvent ???
The code is in an event filter installed on the mdiArea. In the mainWindow's constructor:
Qt Code:
mdiArea->installEventFilter(this);To copy to clipboard, switch view to plain text mode
Qt Code:
{ if (obj == this->mdiArea) { loggerSingleton::Instance()->addDebugString("Found paint event for mdiArea...",0); this->updateMessagesAndLogs(); //QPaintEvent *paintEvent = static_cast<QPaintEvent*>(event); painter.setPen(Qt::blue); painter.drawText(10,10,"Test 123..."); int startAngle = 30 * 16; int spanAngle = 120 * 16; painter.drawPie(rectangle, startAngle, spanAngle); painter.end(); return true; } } }To copy to clipboard, switch view to plain text mode
what happens if u dont write painter.end() ??
Same thing, I've just added it to see if it makes a difference.
I've looked at the paintEvent in the mdiArea source, and there isn't anything really different there:
Qt Code:
{ Q_D(QMdiArea); const QVector<QRect> exposedRects = paintEvent->region().rects(); for (int i = 0; i < exposedRects.size(); ++i) painter.fillRect(exposedRects.at(i), d->background); }To copy to clipboard, switch view to plain text mode
I can't see why it does not work. If I return true in the event filter it should filter the event shouldn't it? Thus, it should only draw whatever I draw in my event filter...
What about:
?Qt Code:
mdiArea->viewport()->installEventFilter(this);To copy to clipboard, switch view to plain text mode
Notice that you'll need to change the eventFilter() implementation accordingly:
Qt Code:
if (obj == this->mdiArea->viewport()) { ... }To copy to clipboard, switch view to plain text mode
Much nicer approach is to subclass QMdiArea and reimplement paintEvent().
J-P Nurmi
Bookmarks