Results 1 to 6 of 6

Thread: Preserving border / antialiasing QWidget on a QGraphicsProxyWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Preserving border / antialiasing QWidget on a QGraphicsProxyWidget

    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:
    Qt Code:
    1. view = new QGraphicsView(scene);
    2. view->setRenderHints(QPainter::HighQualityAntialiasing|QPainter::TextAntialiasing);
    3. view->scale(0.9,0.9);
    To copy to clipboard, switch view to plain text mode 
    Additionally I could improve my PixmapItems this way:
    Qt Code:
    1. this->fotoPixmapItem->setTransformationMode(Qt::SmoothTransformation);
    To copy to clipboard, switch view to plain text mode 
    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:
    Qcombobox.jpg
    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?
    Attached Images Attached Images

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Preserving border / antialiasing QWidget on a QGraphicsProxyWidget

    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).
    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.

  3. The following user says thank you to Spitfire for this useful post:

    sedi (27th April 2012)

  4. #3
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Preserving border / antialiasing QWidget on a QGraphicsProxyWidget

    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:
    Qt Code:
    1. view->scale(1,1);
    2. QPolygonF viewPoly = view->mapToScene(view->viewport()->geometry());
    3. QGraphicsPolygonItem *viewPolyItem=new QGraphicsPolygonItem (viewPoly);
    4. scene->addItem(viewPolyItem);
    5. viewPolyItem->setZValue(1000);
    6. viewPolyItem->setBrush(QBrush(Qt::black,Qt::SolidPattern));
    To copy to clipboard, switch view to plain text mode 
    I see a black rectangle, but it covers merely a quarter of the viewable area.
    Using ->rect yields the same result:
    viewportRec.jpg

  5. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Preserving border / antialiasing QWidget on a QGraphicsProxyWidget

    Use rect not geometry, geometry takes position into account.

    Qt Code:
    1. void MainWindow::resizeEvent( QResizeEvent* e )
    2. {
    3. this->scene->setSceneRect( this->view->rect() ); // this is what you need.
    4. this->rectItem->setRect( this->view->mapToScene( this->view->rect() ).boundingRect() );
    5. this->polyItem->setPolygon( this->view->mapToScene( this->view->rect() ) );
    6. }
    To copy to clipboard, switch view to plain text mode 
    Both approaches will work, but only if you set scene rectangle.
    You should always set scene rectangle.

  6. The following user says thank you to Spitfire for this useful post:

    sedi (29th April 2012)

  7. #5
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Preserving border / antialiasing QWidget on a QGraphicsProxyWidget

    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:
    Qt Code:
    1. MainWindow::MainWindow()
    2. {
    3. createActions();
    4. createMenus();
    5. setWindowTitle(tr("Title"));
    6. statusBar()->showMessage(tr("Ready"));
    7. setUnifiedTitleAndToolBarOnMac(true);
    8.  
    9. this->showMaximized();
    10.  
    11. scene=new QGraphicScene(this);
    12. view = new QGraphicsView(scene);
    13. QHBoxLayout *layout = new QHBoxLayout;
    14. QWidget *widget = new QWidget;
    15.  
    16. widget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    17. setCentralWidget(widget);
    18. widget->setLayout(layout);
    19. layout->addWidget(view);
    20.  
    21. this->scene->setSceneRect(this->view->rect());
    22.  
    23. rectItem->setRect(this->view->mapToScene(this->view->rect()).boundingRect());
    24. //rectItem->setRect(0,0,scene->width(),scene->height());
    25. scene->addItem(rectItem);
    26. rectItem->setZValue(1000);
    27. rectItem->setBrush(QBrush(Qt::black,Qt::SolidPattern));
    28.  
    29.  
    30. view->setRenderHints(QPainter::HighQualityAntialiasing|QPainter::TextAntialiasing);
    31. view->setDragMode(QGraphicsView::ScrollHandDrag);
    32. view->setInteractive(true);
    33. view->setMouseTracking(true);
    34. //view->scale(1,1);
    35.  
    36. //scene->setBackgroundBrush(this->backgroundPic.scaled(screenRect.width(),screenRect.height(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
    37.  
    38. [...put other stuff onto scene...]
    39.  
    40. }
    To copy to clipboard, switch view to plain text mode 

    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)
    Attached Images Attached Images

  8. #6
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Preserving border / antialiasing QWidget on a QGraphicsProxyWidget

    As my question has totally changed its subject I asked it again - in a new thread with a new title - over here.
    Thank you for helping me!

Similar Threads

  1. Replies: 1
    Last Post: 26th April 2012, 19:15
  2. Border-image not working in QWidget?
    By astampor in forum Qt Programming
    Replies: 4
    Last Post: 3rd October 2011, 16:16
  3. Customised QWidget border
    By chandan in forum Newbie
    Replies: 1
    Last Post: 2nd March 2011, 18:08
  4. QWidget's border style
    By luochen601 in forum Qt Programming
    Replies: 2
    Last Post: 13th September 2010, 08:17
  5. Showing QWidget border around the window
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 20th March 2008, 21:14

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.