I'm working on some Qt GUI application with shiny glossy design.
I have a list view customized with my QItemDeleagte subclass. I draw items in paint virtual method. Selected items need to be drawn with glow effect on the border. Normal items must be without glow effect
That's RectangularGlow QML Type which is exactly what I need my view items border to look like. Unfortunately the app was written in Qt 4.7 and there is no way to port the app and all its dependencies to Qt 5.
QGraphicsDropShadowEffect is not sutable since shadow gradient has one direction and an offset. QLinearGradient doesn't help too or I don't know how to use it.
I consider drawing some kind of border image.
Is there any proper and elegant way to implement this using gradients or graphics effects?
EDIT:
As cmannett85 pointed out QGraphicsDropShadowEffect seems to be ok. However graphics effect may be installed on a whole paintdevice and for view item i cant just draw only selected item border rectangle with glow effect and leave other elements in a normal state. Instead all drawing on a list view affected
EDIT2:
I found a solution in an answer for another question. So I think this question may be closed
Related
I am working on updating an application for a client.
They use Qt and currently use a QGLWidget to display a full-screen view of 1 of 4 possible cameras selected by clicking the appropriate radio button. They then use OpenGL to draw on the image being displayed. This works great, but they want to update the UI to include a quad-split view of all 4 cameras.
My first thought on how to accomplish this was to keep the one QGLWidget for the full-screen display, and have 4 small QGLWidgets for the quad-split. From the documentation I found that you can't overlap QGLWidgets or QOpenGLWidgets because they don't handle z-order appropriately, but that this can be accomplished by using QOpenGLWindows and QWidget::createWindowContainer.
So, I coded up an application that uses a QOpenGLWidget (trying to bring them up to date) for the full-screen view, and 4 smaller QOpenGLWindows using QWidget::createWindowContainer, but this isn't working either.
The widgets built from QOpenGLWindows are always on top even if I use lower() to try to get them behind the full screen QOpenGLWidget. I've also tried using hide() on the widgets built from QOpenGLWindows, however, this has had no effect.
Do this at a lower level. Keep the one QGLWidget -- in fact don't touch your Qt objects. Instead, change the lower-level rendering so that it makes 4 calls to glViewport.
After each call to glViewport, update the modelview and projection and matrices according to the camera of interest, then draw the 3D scene.
This is simple and performant, because the driver only needs to deal with a single OpenGL context. You might have some extra work to adjust mouse input, but I think it'll be worthwhile.
How to put a label or button into qt3d window? Is it possible? Havent seen any example... I was trying to simply put qt3d in windowcontainer, assign layout to it and layout->addWiget() but it just doesnt work.
I know this is a farily old question but I wanted to give a more detailed answer if anyone else stumbles across this.
I implemented a Qt3D widget which you can find here. Unfortunately it relies on a method to obtain the texture id from QAbstractTexture which is only available from Qt >= 5.13 so that's the minimum version you have to use.
createWindowContainer draws the respective window above everything else. So you'll never be able to draw any buttons inside the container.
You can of course have buttons and everything else around your containered 3D window. But that's specifically not what you wanted.
You can use Dear ImGui - and it's Qt3D integration. ImGui is used to draw GUI elements using vertices in 3D environments.
Of course you can always use QML - there you should be able to place buttons inside the 3D view.
you have both label and (radio)buttons on the first example for C++ into the QT3d documentation, refer to Qt 3D: Basic Shapes C++ Example
QExtrudedTextGeometry seems to be the class for 3D text
I have a Qt application that I am porting to mac.
There are some objects (images) shown in QListView or QTableView, in IconMode, that, when selected, in Windows and Linux get highlighted (a rectangle holding the object, which has colored background - gray if the item is selected but no focus, light blue if the item has focus, slightly more intense blue if the item is selected and has focus - this is probably the default behavior for selection, based on selected color scheme).
On mac the only thing that shows is a tiny dot under the object, and if the object in the view is transparent, light blue shows inside the object - but no selection rectangle. Nothing changes if the object has focus, and if the object is not transparent, only the tiny dot under the object shows.
Once objects are moved on the canvas, mac shows selection as needed, on a bounding rectangle, only inside the listview and tableview the bounding rectangle is invisible.
The form was created using the Designer... the listView property QListView.selectionRectVisible is checked.
I can't see what makes that happen... but I have tried
#if defined (Q_OS_MACX)
m_ui->lv1->setAttribute(Qt::WA_MacShowFocusRect, true);
m_ui->lv1->UseCustomSelectionColors(true); // documentation shows this but it doesn't build
m_ui->lv1->setSelectionRectVisible(true);
#endif
for the mac, and it does not make any difference.
What else can I try, to show selection of objects ?
Qt 4.8
Edit: found a site that has an example for a tiled list view... among other things it draws a visible rectangle around the selected items...
It seems like a very complicated way to do something that seems to be already implemented - highlighting a selected object - I will do it if I have to but I am hoping that I do not have to add something too complicated for the mac version, that will not be used in any other platforms...
There has to be a way to use the normal properties and methods of listview and tableview to make sure that the background of the bounding rectangle, not just the background of the item, shows when a selection is made ?
I don't know if this is a typical mac behavior...
Update
While I really try not to overwrite the desired default system behavior, I tried to force list behavior...
#if defined (Q_OS_MACX)
QString stylesheet = "";
stylesheet += "QListView::item:selected:active:hover{background-color:red;}";
stylesheet += "QListView::item:selected:active:!hover{background-color:blue;}";
stylesheet += "QListView::item:selected:!active{background-color:yellow;}";
stylesheet += "QListView::item:!selected:hover{background-color:green;}";
setStyleSheet(stylesheet);
#endif
The problem is, I need the system colors, I cannot define my own since they will not match the rest of the app window...
What are the names of the system colors for hover, select (strong), select (but no focus), select (but not active) ?
I have tried using
stylesheet += "QListView::item:selected:active:hover{background-color:Highlight;}";
In windows, this looks ok - because it probably is not recognized so it is ignored... On mac, still ignored. And I have not seen any other names for backgrounds. I tried it with lowercase as well.
I ended up using a style sheet - as in the update to my question - with hard-coded color values for the osx blue theme.
I am trying to set up a GUI using plugins. In my current phase I need the user to click and specify locations of points.
The plugin architecture I have setup requires the plugin to return QGraphicsItem that the plugin wishes to use. In the main program (which future plugin writers won't have access to), I set a background image to guide clicks. The plugins can sneakily access the scene() using an itemChange() and installing an eventFilter() on the scene being set. This allows for the plugins to have access to scene clicks and process whatever information it needs. However, the background picture is being returned by itemAt() calls.
I wish to prevent this background Pixmap from returning with an itemAt() for all future plugins. Is this possible?
Tried:
setEnabled(false); //No success
This doesn't answer your question directly, but it should solve your problem: I suggest reimplementing QGraphicsScene::drawBackground() and drawing your pixmap there. That's what the method is for.
A similar approach would be to put the pixmap in a resources file, then use style sheets to set it as the background of either the QGraphicsView or its viewport widget (I think these have slightly different effects).
To make an item invisible to itemAt() (or any of the other collision detection methods) you can make the boundingRect() method return a QRectF with zero width and height.
This though has the side effect of making any of the partial viewport update modes of QGraphicsView malfunction, because QGV doesn't have any idea where the item is going to paint itself. This can be remedied by having QGV do full updates on every repaint (setViewportUpdateMode(QGraphicsView::FullViewportUpdate)). Depending on your scene this might be an acceptable compromise. If you're using the OpenGL graphics backend the viewport updates will always be full updates anyway.
After so many years, here is the answer.
Make your own subclass of QGraphicsItem and override the shape() method
QPainterPath shape() const override
{
return {};
}
Ref to docs: https://doc.qt.io/qt-6/qgraphicsitem.html#shape
The shape is used for many things, including collision detection, hit tests, and for the QGraphicsScene::items() functions.
So this will effectively make the item invisible for itemAt() and others.
And you still have the boundingRect() which is used to filter what items should be painted.
I've been using label to display images. I'd like to be able to click and create a bounding box then be able to drag the cursor to move around in the image. What would I need to do this? Thanks.
I'm not 100% sure I understand what you are trying to do, but I think the QGraphicsScene is what you are looking for. You can (among many other things):
Render images (QGraphicsPixmapItem, for example)
Change the zoom level when rendering the scene on a QGraphicsView.
Select things using a "rubber band"
Move items around with the mouse (see QGraphicsItem::ItemIsMovable)
etc.
You may need to get familiar with Qt's graphics view framework.