placeholder image for QGraphicsView in Qt Designer - qt

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

Related

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

QToolBar: styling 'show more' button

Does anyone have idea on how to style this rectangular button -which is a default child of a QToolbar?
First two images show the button when the graphical interface is on normal screen mode. It appears; since toolbar icons don't have enough space. Third picture shows fullscreen mode, in which my icons have space.
I want to style its shape, so that it has a radial border, without a corner. This will cancel its ugly look, in second image.
I want to let users use the interface in normal view, so locking application to fullscreen is not an option. I do want to use the button, so removing is not acceptable. Styling its position to 5 pixels left or replacing it with another stylable button could be possible solutions, but I couldn't manage to do them.
I played a lot with toolbutton and pushbutton stylesheets, but had no luck on styling this small button. I am pretty obsessed about my graphical design, but don't want to waste too much time (if solution is not trivial, I will change my toolbar to a rectangular one).
Thanks in advance.
I found the solution by listing the children object names of my toolbar.
QStringList list;
for(int i=0; i<toolBar->children()->size(); i++)
list.append(toolBar->children()[i]->objectName();
Inside the list, there is only one object that has a default name (not " "). It is qt_toolbar_ext_button
Then I was able to style it as:
"#qt_toolbar_ext_button { //... }"
I know this has been answered, but for anyone who needs to know the answer its a "QToolButton" and if you need to style a specific button with an object name you do "QToolButton#objectName" in an external resources file stylesheet or in the Widget UI stylesheet dialog for different objects.
QToolButton#objectName {
}
Check out the documentation - http://doc.qt.digia.com/4.2/stylesheet.html
This gives you the syntax for stylesheets in Qt, or "QSS" files.
Just do it: Qt documentation about stylesheets

Qt quick controls - where is defined ScrollView orientation?

i created my custom style for ScrollView, but actually i don't know how to check what orientation of scroll is it (horizontal or vertical? I need use different image for each of them).
source code of scrollview style
In this source code, that i found, is used word horizontal, but where it comes from? I don't see any declaration of horizontal property.
It comes from this line. In newer versions of Qt, properties for style components are exposed through the styleData object; this is now standard practice for all Qt Quick Controls styling. In the case of ScrollViewStyle, commit e0c8035c updated the code to use styleData instead.

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