Multiple Layers in Widget - c++

I currently need a small ImageViewer in my project, where you can zoom in and go to next or previous image. These buttons should be fixed at right bottom corner like in this picture:
In this case I have q QLabel which has a Layout with some buttons. But now it should be zoomable, so I need QScrollArea, like explained here. But how I add my buttons again in this example? It is possible to archive this view just with QtDesigner?

Maybe QToolBar will suite your needs. It will make a floating panel over your graphics view. An example. If you need to achieve the background of the toolbar transparent while its buttons are semi-transparent then it is doable as well. But first you need to decide if toolbar works for you.

Related

Qt Scroll area can't scroll

I have a problem with QScrollArea, I want to make a scrollable design, because standard window is not enough for me. But, I can't scroll it down and add / see new content. I don't know why. I want to set for eg. 1600 px scroll area height and make a layout to it in Desiner. But in this situation I can't scroll it:
I heard a tip to add a layout to ScrollArea, but I don't want to use it, I want to make a layout myself.
I have tried to uncheck 'widgetResizable'
So is it any other method to scroll this widget?

Implementation of gui designer

I'm interested in making my own small gui designer for learning purposes in Qt. Just basic drag and drop from left panel which would have controls, to right panel on which they could be selected, moved, resized and have their properties changed (name and such) and eventually (if selected) be lined up.
I would use QGraphicsScene as the right panel cause it already has selecting and moving implemented. But how would I implement resizing? And then how would I generate a QWidget class with controls at same positions? Or is there an easier way?
What would be the best way to implement all of this? All suggestions are welcome and keep in mind that it won't be complex as Qt designer.
You need to define some widgets, which are going to be dragged from the left panel -maybe a tree view with icons- and dropped to the scene.
These widgets should inherit from QGraphicsWidget. You can also inherit QWidget and put the widgets into scene via QGraphicsProxyWidget. They can be resized by highlighting corners and overloading the mouse events. Please check out corner grabbers and sizable box examples. Also check out QSizeGrip. It is the resizing grip of any QStatusBar.
Property panel is the easiest, you should list the properties of the clicked item. To line up, you can reinvent the wheel and write a layout maker class, or simply use QGraphicsLayout and highlight the layout on your interface. Ctrl+left click should select multiple widgets, a layout button should layout them programmatically, and a bounding rectangle item should be drawn.

Specific QPushButton style

How can I customize the look of a QPushButton or QToolButton to look something like elementaryos's webpage "buttons"?
All I really want is the characteristic image position and the text on it's side, maybe if i'm lucky i can also get a border like that, but i don't really need the little description below the title :)
Can i do it only with StyleSheets, or do i have to subclass QPushButton/QAbstractButton/Something like that? I already searched everywhere but didn't found that level of customization without things like painting something in a fixed place, which is exactly what i don't want.
EDIT:
I really would like a solution that would get me a customizable button, not a fixed image one, something in the tracks of
MainWindowButton(QString(title), /*opt*/QString(description), QImage(icon));
There are a number of approaches that may work.
You might first consider trying to compose a solution with a normal QPushButton with a QVBoxLayout on it. You could add three QLabels; one for the title text, one for the caption text and one for the image. Some CSS could probably be used to render the background image of the button for up and down and more CSS to style the text in the two labels and position the image on the third but you would then find that the labels don't shift down when the button is clicked.
I think the best solution involves direct painting. You could do this by sub classing a QWidget and overriding the paintEvent(). Render everything for the up state and shift everything over and down a bit for the down state.
You could achieve this without sub classing by rendering the up and down states to a QImage and styling a QPushbutton with them using CSS.
There are a number of combinations of these approaches too.
You can set the background as white with the icon in the right corner with some creative use of the border-image stylesheet property where the bottom border is as tall as the icon and the top, left and right borders are 0 pixels wide. You'll need to make a custom image that basically looks like the icon with a couple pixels width on the left and top that are white
http://doc.qt.digia.com/qq/qq20-qss.html#theboxmodel
The text you may have to do overriding paintEvent.

Qt splitter layout resize behaviour using Qt Designer

I have an issue with size in my view made in Qt with drag and drop.
Let me start with an image to help me explain
This is the mainwindow for my form.
What happens is:
We have 4 tab widgets. the left tab widget has a horizontal splitter to the 2 mid widgets.
The 2 mid widgets have a vertical splitter, and a horizontal splitter on the left and right side.
The right widget has a vertical splitter on its left hand.
So all views are connected using splitters.
Lastly the mainform sticks every thing together in a resizable way using horizontal layout.
The problem is, the width of the leftmost and rightmost widgets are fixed (in designer).
I want them to be smaller in width. Something similar to:
You can see the widgets are resized. I was able to do this running the application, and manually adjusting the splitters. Is there a way in QtDesigner to do this? I tried playing with policies. I didn't really get any further however. Does this indicate a lack of knowledge of my part about policies? Perhaps layouts in general?
What options should I use to achieve the desired layout using QtDesigner. I want to avoid using code.
Hope I will be able to solve this soon. It must be overlooking something simple..
You can play with the "Horizontal Stretch" and "Vertical Stretch" properties to change the position of the split.
For example with both the vertical stretch of the top central QTabWidget and the horizontal stretch of the central QSplitter at 1 and all the other values kept at 0, you'll get the result you want.
When you have multiple non-zero stretch values, the result of the ratio (e.g.: vertical strech at 2 and 1 for the 2 central QTabWidgets => 2/3 and 1/3) is not visible in the designer but seems to be working when you run the application.
PS: You can also achieve the same result with tabbified QDockWidgets but the dock tabbification is not possible through the designer only.
I set start position that:
QList<int> list= ui->splitter->sizes();
list.replace(0,this->height()/0.3);
list.replace(1,this->height()/0.7);
ui->splitter->setSizes(list);
and remember to minimum size child widget

How to prevent an icon being highlighted?

I have a listwidget with items which have icons. When the item is selected both the text and the icon are highlighted. My problem is that when the icon is highlighted it just goes entirely black because I'm using only two colours. Is there a way to prevent the icon from being selected?
You can add additional images to the QIcon, depending on it's state:
QIcon icon(...);
icon.addFile("selected.png", size, QIcon::Selected);
See also the documentation of QIcon::addFile().
Best solution was to make your own qstyle which handled the painting of the backgrounds of listitem sub controls and draw the icons qrect as white
Another possibility would be to reimplement QListWidgetItem... You could therefore have a bigger control on how things gets done during the process of selection and painting...
Of course, it's a lot more work...