PDA

View Full Version : Preserving border / antialiasing QWidget on a QGraphicsProxyWidget



sedi
25th April 2012, 22:11
Hi,
I have a QWidget, filled with some QPushButtons and QComboBoxes, which lives in a QGraphicScene, as courtesy of a QGraphicsProxyWidget.
When i scale the QGraphicsView to a smaller size there are a few ugly things.

I expected these (good old Nyquist), but I also expected to get rid of them (more or less) with a good antialiasing:

view = new QGraphicsView(scene);
view->setRenderHints(QPainter::HighQualityAntialiasing|Q Painter::TextAntialiasing);
view->scale(0.9,0.9);
Additionally I could improve my PixmapItems this way:

this->fotoPixmapItem->setTransformationMode(Qt::SmoothTransformation);
Now the Pictures look ok, I can live with some rather ugly text antialiasing, but...

...I still have a problem with my widgets:
Here you see a screenshot snippet of a QCombobox which lost its left black border line:
7627
FYC I have attached an enlarged (4 times, Photoshop) version of the same screenshot in the attachments.

Is there any way to ensure that the border line is at least one pixel wide? Or to set up a better antialiasing for the widgets? I want the view to be user scaleable to better fit onto various screen sizes. Is scaling perhaps a stupid Idea in the first place?

Spitfire
27th April 2012, 09:25
Depends on what you need, but I would advise against scaling.

You will run into plenty of such issues which are very hard, or impossible to solve using shortcuts (like proxy widget).

You can safely assume that most of computer screens today is 1080p or thereabouts (98% according to this website (http://www.w3schools.com/browsers/browsers_display.asp)).
Even tablets and many smartphones fall into that category.
Is your target audience really that 2% minority with 800x600 or smaller screens?

It may be better idea to detect screen size and adjust widget/font sizes (if necessary) on application startup.

sedi
27th April 2012, 12:33
Thank you very much for this advice, I will heed it. Currently I try to detect the size of the view, but viewport->rect or viewport->geometry don't seem to be correct for this matter. I use this code to just paint a rectangle into the scene, of the same size as the view:

view->scale(1,1);
QPolygonF viewPoly = view->mapToScene(view->viewport()->geometry());
QGraphicsPolygonItem *viewPolyItem=new QGraphicsPolygonItem (viewPoly);
scene->addItem(viewPolyItem);
viewPolyItem->setZValue(1000);
viewPolyItem->setBrush(QBrush(Qt::black,Qt::SolidPattern));
I see a black rectangle, but it covers merely a quarter of the viewable area.
Using ->rect yields the same result:
7636

Spitfire
27th April 2012, 15:12
Use rect not geometry, geometry takes position into account.



void MainWindow::resizeEvent( QResizeEvent* e )
{
this->scene->setSceneRect( this->view->rect() ); // this is what you need.
this->rectItem->setRect( this->view->mapToScene( this->view->rect() ).boundingRect() );
this->polyItem->setPolygon( this->view->mapToScene( this->view->rect() ) );
}

Both approaches will work, but only if you set scene rectangle.
You should always set scene rectangle.

sedi
28th April 2012, 00:38
Thank you very much, Spitfire. Unfortunately I still don't get it done, to "know and use" the viewable portion of the scene.
I think there will probably be a very stupid beginner's mistake either in the setup of widget, layout, scene & view, or in their calling order.

I tried so many changes that I start to be really confused.

The code I use:

MainWindow::MainWindow()
{
createActions();
createMenus();
setWindowTitle(tr("Title"));
statusBar()->showMessage(tr("Ready"));
setUnifiedTitleAndToolBarOnMac(true);

this->showMaximized();

scene=new QGraphicScene(this);
view = new QGraphicsView(scene);
QHBoxLayout *layout = new QHBoxLayout;
QWidget *widget = new QWidget;

widget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy:: Expanding);
setCentralWidget(widget);
widget->setLayout(layout);
layout->addWidget(view);

this->scene->setSceneRect(this->view->rect());

QGraphicsRectItem* rectItem = new QGraphicsRectItem();
rectItem->setRect(this->view->mapToScene(this->view->rect()).boundingRect());
//rectItem->setRect(0,0,scene->width(),scene->height());
scene->addItem(rectItem);
rectItem->setZValue(1000);
rectItem->setBrush(QBrush(Qt::black,Qt::SolidPattern));


view->setRenderHints(QPainter::HighQualityAntialiasing|Q Painter::TextAntialiasing);
view->setDragMode(QGraphicsView::ScrollHandDrag);
view->setInteractive(true);
view->setMouseTracking(true);
//view->scale(1,1);

//scene->setBackgroundBrush(this->backgroundPic.scaled(screenRect.width(),screenRect .height(),Qt::IgnoreAspectRatio,Qt::SmoothTransfor mation));

[...put other stuff onto scene...]

}

The result should be a black rectangle covering the entire screen. In fact, the rectangle it is occupying a much smaller size, which I can't understand for the life of me... (see JPG)

sedi
29th April 2012, 03:12
As my question has totally changed its subject I asked it again - in a new thread with a new title - over here (http://www.qtcentre.org/threads/48760-Getting-size-of-a-QGraphicsScene?p=219228#post219228).
Thank you for helping me!