How to disable antialiasing for a widget? - qt

For reasons that are out of my control a widget has to be rendered without antialiasing. It used to be painted all by in house written spaghetti code with render hints:
painter.setRenderHint(QPainter::Antialiasing, false);
painter.setRenderHint(QPainter::SmoothPixmapTransform, false);
Now I'm rewriting that widget as inherited from QWidget and using QTs own QLabel, QButton and style-sheet. Is there a way to disable antialiasing for a widget and it's children?

Related

placeholder image for QGraphicsView in Qt Designer

I often have UIs that use QGraphicsView. At run time, I can put all sorts of wonderful things in my scene. However at design time in Qt Designer(Creator), I'd like to have some sort of placeholder image shown to help me visualize what the UI will really look like.
I cannot find a property for setting some kind of background image. I tried various settings in the styleSheet property, but nothing displays, e.g.
QGraphicsView: {
background-image: speedo.png;
}
It is possible, you just use the wrong syntax:
QGraphicsView {
background-image: url("/path/to/your/image.png");
}
QGraphicsView is a QWidget, so you can use the Qt Style Sheets Reference to design your widget with the allowed properties

Offscreen rendering with QQuickFramebufferObject

I'm trying to experiment with offscreen rendering with QQuickFramebufferObject. It appears that I cannot do it -- if I try to bind a FBO to render offscreen, the framebuffer ends up being permanently blue after I release the FBO and attempt to render to the framebuffer.
To make sharing code easier, I've uploaded an example to https://github.com/sohailshafii/textureinsgnode_offscreen. It is basically the "textureinsgnode" Qt example modified to include a FBO that can be rendered to. Right now in the render function of fboinsgrenderer (https://github.com/sohailshafii/textureinsgnode_offscreen/blob/master/fboinsgrenderer.cpp) I disable offscreen rendering:
// uncomment this block of code to see an incorrect rendering
/*m_fbo->bind();
logo.render();
update();
m_fbo->release();
m_fbo->bindDefault();*/
logo.render();
update();
But once I uncomment the FBO here, I get a solid blue screen. I've viewed offscreen rendering examples in QT but unfortunately they don't describe how it's done with QQuickFramebufferObject. I'm running QT 5.7.1.

How to add QWidget to a QGLWidget

What is currently the best way to add a QWidget to a QGLWidget as a child? In this case I want to add a QSlider to QGLWidget, however it seems like half the links on Google point to dead information now so it's tricky working out what the current way to achieve this is.
I did try creating a QSlider as a child and setting the geometry, but that didn't seem to do a lot.
Child widgets don't work with a QGLWidget, that's documented.
Use QOpenGLWidget and the child widgets will work fine. There's nothing special to do in this respect, simply add child widgets, layouts, etc., and it "just works".

draw qt widget bigger as the mouse hovers over it (overlapping of widgets)

I would like to create a simple effect with my qt gui, but i have no idea how to achieve this.
I have several widgets, that i implemented as subclasses of qwidget. These are part of another widget and live in a layout. When the mouse hovers over these widgets, i want them to appear bigger to highlight the selected one.
This is what i already tried:
Override the paint event, and simply paint it bigger. But then, the other widgets that also live in the same layout overpaint the oversized areas.
I also tried to call the paint function "by hand" from the parent window, to get control over the painting order. But that didnt help either.
I think there has to be a possibility achieving this effect this qt, but i simply dont know how.
Any ideas?
You could either:
create your GUI inside a QGraphicsView, with QGraphicsWidgets and use setScale when the mouse enters or leave the widget, or
use QML.

Scalable painting of a Qt application

I'm writing a simulation of an embedded device's screen (which contains custom widgets on top of a main QWidget), and while the native size of the screen is 800x600, I want to be able to scale it up and down by dragging the window's corner. Without diddling with grid layouts and stretchers (which won't scale the fonts up/down), how do I accomplish this sort-of zoom? I think part of the solution might be to create a QTransform and somehow inject that into the QWidget for the entire application, or its QPaintDevice or QPaintEngine. I'd like to do this without putting QTransform in each custom widget, just the "main window" QWidget.
This is possible if you are using QGraphicsView as your main display widget. QGraphicsScene now supports widgets as content, so you can literally just scale them.
I believe the alternative is to reimplement the paint() for each widget, and manually set the transform/scale before the painting of child widgets.
Bit of a guess here as I've not tried it... but you could try putting the top-level widget into a QGraphicsView then get the QGraphicsView to do the scaling.
You could then enable OpenGL on the QGraphicsView and have it scaled in hardware so it's nice and fast.

Resources