How to place one widget over another in Qt - qt

i have a window in Qt, on that i am drawing a picture. now i want to place the progressbar over it.
how can i do that?..
steps i am following to do
Create a window,
Draw picture in paint event of window
Then create QGridLayout layout, add your window
Display over it.
suppose i want to add progress bar, over a portion of picture window. how can i do that
i dont think its possible to implement in window paint event.
please assist me
Thanks

You can add the progress bar as child of your QWidget without adding it in the layout. This will draw the QProgressBar into the QWidget. Since you are not using the layout you will have to manually manage the position of the QProgressBar.

I think that just adding a progress bar widget to your grid layout should work.

Related

QT layout manager does not recover space when hiding widget until window is moved

I am using Qlabels to plot some graphs and images (via setpixmap).
My basic layout is:
QVBoxlayout main layout via qdialog's setlayout.
QHboxlayout (array of QLabels)
Qlabel expandedPlot (optional expanded plot of one of the above QLabels)
QLabel mainImage Main image display
Within the QDialogs re-implemented keypress event handler, I hide()/show() the expanded plot. When I hide() the expandedPlot, the layoutmanager recovers about 1/2 of the vertical usage. Then when I drag the window, the layout manager recovers the remainder of the vertical space (as if there was no item present).
How can I force the behavior of moving the window? I want the layout manager to completely recover the vertical space.
I am using Qt 5.6 on windows, but want cross-platform solutions.
Thank you, mike
Because laying out the widget is quite expensive, Qt doesn't always do it. If you change the size of enclosed widgets you are likely to need to call updateGeometry on them to trigger the enclosed layout manager to re-layout. But if you hide the widget, updateGeometry does nothing. In that case you need to call adjustSize on the parent widget, which will then trigger the re-layout.

arange horizontal line of buttons in Pyside/PyQT/Qt

I want to create a simple GUI with PySide/PyQt.
In this GUI I want to have a raw with severeal push buttons and the length of the buttons I want to be proportional to its text label.
Looking at QPushButton and QHBoxLayout I don't see a posibility this can be done easy.
Any advice in this respect?
Thanks
Dimitar
This is easy to do with Tool Buttons. In Qt Designer:
Create the tool buttons and set the text
Put them in a horizontal layout
Add a horizontal spacer to the beginning and/or the end of the layout
Optionally, you could also:
Set a minimum width/height
Change the size-policy of the buttons to minimum/minimum

How can I make a QMenuBar item appear over its QMenu

First of all, I'm fairly new with Qt and Qt Creator so go easy if this is a stupid question.
I was practicing using Qt Creator, playing around with css styles. In particular, I'm trying to get the menubar and its menus to look something like this (on Windows): http://i.stack.imgur.com/9lMnQ.png.
However, the closest I've been able to get so far is this: http://i.stack.imgur.com/5Nlen.png.
I've searched online to see if anyone has tried something like this but I wasn't able to find anything.
The only possible solution I can think of is if the menubar item (with no bottom border) could be rendered in above the menu, so that they overlap, covering its top border over the width that they overlap.
If that won't work or is impossible or whatever please do suggest any other solutions/workarounds/hacks.
Thanks in advance!
I think that the only good solution is to avoid any tricks and create a new widget:
Create a new class inherited from QWidget with Qt::Popup attribute.
Place a QMenu into a layout of the widget.
Get a position of QMenuBar item which is clicked using QMenuBar::getActionGeometry.
Calculate position of the widget and of the tab in the widget to be placed over the menubar item.
Customize form of the widget using QWidget::setMask to make it look like a rectangle with a tab.
Show your widget instead of QMenu.

How to prevent QTableWidget from occupying the whole window in a QHBoxLayout?

In my Qt program, I programmatically generate a modal QDialog. I want to show two widgets in this dialog window: A custom widget showing a camera output and a QTableWidget, showing the pixel coordinates of the corners found in the camera image. I generate a QHBoxLayout and add my custom widget and the QTableWidget into it. Then I set this QHBoxLayout as the Layout of the QDialog window. What I want to achieve is to share the available space in the QDialog's window area equally between my custom QWidget and the QTableWidget, horizontally, by using a QHBoxLayout. But I always end up with QTableWidget occupying the whole QDialog area, by overlapping my custom widget. How can I instruct these two widgets to exactly share the QDialog area?? Note that I first add my custom widget and then the QTableWidget into the QHBoxLayout.
Make sure on your custom widget you've specified a minimumSizeHint and a sizeHint, this instructs the QLayout manager that the widget requires a specific space. To have them split equally you'll be best off detecting the size of the QDialog and then specifying the width for both by removing the boundary sizes (spacing between widgets + space to QDialog edge) and dividing it up.

Central QWidget [Qt]

I have main window and in this window I have QListWidget. I want this list to be central widget in the main window and I know that I can do that by writing code like setCentralWidget(QWidget*) and it works (list is spread on the whole mainwindow) but this isn't reflected in designer when the list is still in this same position and has the same size. Is there any way to make it so the change is visible in designer as well as in the code?
Thank you.
In Designer, right click on an area of the form next to the QListWidget, then choose Layout->Layout Horizontally (or vertically, almost anything is acceptable).
I figured it out. In order to do so I had to choose grid layout for main window and sizePolicy for list as Prefered.

Resources