Problems with selection region drawing on Qt4

Hello!

I need to draw a rectangle on the QGLWidget for selection by region on the OCC 3D Viewer. The problem is: when I drawing the rectangle using QPainter, I see the white backgrount of the parent Widget. In the Qt3 such problems was not appeared. At the OCC Qt3 samples they using the simple QWidget with some additional flags. But this did not work on Qt4, only QGLWidget can be resised properly on Dt4. Who knows, how to solve this problem?
My code is:

Q3VBox* vb = new Q3VBox( this);
vb->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
myView = new View(vb);

..............

View::View(QWidget* parent) : QGLWidget( parent)
{
int windowHandle = (int) winId();
short hi, lo;
lo = (short) windowHandle;
hi = (short) (windowHandle >> 16);
Handle(WNT_Window) hWnd = new WNT_Window(Handle(Graphic3d_WNTGraphicDevice)::DownCast(myContext->CurrentViewer()->Device()),(int) hi,(int) lo);
myView->SetWindow( hWnd );
..........
}

void View::DrawRectangle(const int MinX, const int MinY, const int MaxX, const int MaxY)
{
QPainter thePainter(this);
thePainter.setPen(Qt::white);
QRect aRect;
aRect.setRect( MinX, MinY, Maxx, Maxy);
thePainter.drawRect(aRect);
}

Rob Bachrach's picture

In Qt3, you probably had a call to setRasterOp(Qt::XorROP) to cause the rectangle to clear and redraw with the mouse movement. This was removed from Qt4 (much to my dismay). You might want to look at the QRubberBand class to achieve a similar, although not as nice, result.

asofin's picture

Rob,

Thenk you very much for advise! Could you, please, tell me also, how to use QRubberBand for this case?

asofin's picture

Rob,
I understood what is a QRubberBand class, so you don't need to ansver my question. I think, this is a good solution.

Markus's picture

Hello,

did you solve your problem?

Could you give me a hint how to programm a simple OCC Viewer with QT4?

Markus's picture

Hello,

did you solve your problem?

Could you give me a hint how to programm a simple OCC Viewer with QT4?

Thx!
Markus

asofin's picture

Hello, Markus,

Yes, I solve my problems thanks to your advice.
As for OCC viewer on Qt4, I simply took the viewer from Qt3 sample from OCC samples and changed the Qt3 objets to Gt4 support objects. To do that you only need to change the Class names to Qt3 support class names. For example QAction -> Q3Action and so on. May be you need to change something else, but now I forgot what exactly.

Markus's picture

Ok, that's one possibility that i haven't think about. But is it possible to take advantage of the QT4 expansions and new classes? I mean, can i mix up Qt3 support classes and the new Qt4 classes?

Thanks!
Markus

asofin's picture

Yes, you can use Qt3 support classes and the new Qt4 classes in the same code. You can also redesign the all classes at the Qt3 viewer to Qt4, but it would be more difficult, then to simply use Qt3 support classes.

Markus's picture

Hello,

my project now compiles with the qt3 support classes. But when i try to start it comes to an "segmentation fault" - have you maybe an example qt4-app or something?

asofin's picture

No, I had not such problems.

asofin's picture

Unfortunatelly I have not a simple examle of Qt4 application with OCC viewer, only a big commercial application.

Jan Brüninghaus's picture

Debugging could help. ;-)

Have a look what statement causes the segmentation fault with a debugger and check out the values of all used variables at this point.

P Dolbey's picture

Markus,

I don't know if your still moitoring this thread. I've now worked out the minimal need for a purely Qt4 based viewer - with minimal flicker on resize but I still think its running 2 paint events for each resize event. I've attempted to isolate the specific functionality of the viewer in a specific widget, delegating all the context construction to a widget test harness for now. And QRubberBand is working well in this widget for boxing group selections so long as you set setAutoFillBackgound(false) in the constructor plus aWNTWindow->SetFlags(WDF_NOERASEBKGRND) when the OCC view window is created.

Pete

P Dolbey's picture

Markus,

I don't know if your still moitoring this thread. I've now worked out the minimal need for a purely Qt4 based viewer - with minimal flicker on resize but I still think its running 2 paint events for each resize event. I've attempted to isolate the specific functionality of the viewer in a specific widget, delegating all the context construction to a widget test harness for now. And QRubberBand is working well in this widget for boxing group selections so long as you set setAutoFillBackgound(false) in the constructor plus aWNTWindow->SetFlags(WDF_NOERASEBKGRND) when the OCC view window is created.

Pete