MoveLeft() not working
-
I want to centre a widget on the screen using
@widget->rect().moveLeft(x);@
checking left() before/after this line of code returns 0 even though the widget is not on the far left of the screen at any point. Widget has not moved. (Calculation for x is returning sensible number).
-
I think you can't change the position of the menu bar with code.
-
QWidget->rect() returns a QRect, not a QRect& (a reference to a rect). That is, it is a copy of the rect of your widget, but that rect is not connected to the rect of the widget itself.
What you need to do, is get the widget geometry, adjust it to your liking, and then set the result on the widget again with the setter.
-
So why does this not work - at the end of my method I check the QlistView geometry and it is correct (with the new values AND the listView is updated on screen) but looping through the next time it has the old values
@ QRect screenRect = geometry();
QRect menuRect = ui.menu->geometry();menuRect.getCoords(&x1, &y1, &x2, &y2);
screenRect.getCoords(&screen_x1, &screen_y1, &screen_x2, &screen_y2);
int width(menuRect.width() * 1.5);
x1 = (screen_x2 - width)/2;
x2 = x1 + width;
menuRect.setCoords(x1, y1, x2, y2);
ui.menu->setGeometry(menuRect);@ -
You would think, right?? I tried that first but it is not getting applied when the window loads so the first positioning of the listView is wrong. Having worked with all the different repositioning options I can see it is something to do with loading the main window because they all give the same result.
My software uses Ctrl+F12 to increase the font size of the listView and therefore reposition the listView (since everything is bigger) and that positions everything fine, so the code is working - when I start the app it is running through the Ctrl+F12 code but not putting the listView in the right place (positions it as it is in the ui).
I am doing the reposition code after window.showFullScreen() so the mainwindow.geometry() is accurate for calculations but the listVeiw STILL positions as per the ui even though my numbers are accurate and the reposition code is the last thing done, no other code after it. Frustrating :-S
-
Why can't you use layouts? They handle size changes of widgets fine without any magic.
-
Tried that but things start over lapping themselves and I lack the experience to get that working. I basically need a specialised 'zoom' (product is for visually impaired).
If you can tell me how to I can do it I will try anything :-)
- Top of screen - scrolling text area, 3 tool buttons with icons all in a line.
- Underneath - centred label.
- Main part of the window - listView
Users need to be able to increase the size of 3 with 1 & 2 staying the same size and increase 1 & 2 with 3 staying the same size.
Need to cope with 200pt font.
-
How can you have 3 stay the same size while 1 & 2 change theirs when e.g. full screen? Apart from that requirement layouts should work very well. I don't see how things can start to overlap once they are in a layout.
-
That is what I have to sort out - works fine in the old VB code.
OK, so if I start a new project with a scroll area and 3 buttons on the main window I notice that if I click "horizontal layout" and increase the size of the items things are ok. If I select the items and click "horizontal layout" things do not work correctly (that is what I have been doing with the stuff at the top because I do not want the listView in the layout). So this is where the problem is coming in - seems as if layouts only work correctly if the whole window is in one layout.......... I need the top and bottom to behave independently. So I basically need to create a widget for the top and one for the bottom so they can each have their own layouts??
Sorry if I am being thick but I have never done Gui (or used Qt) before, always been the back end pointers and long numbers bod.
-
Layouts can be nested. You can also put QWidgets with layouts into layouts.
Read up on layouts and play around a bit with qt designer. That is a really nice tool to quickly try out UIs.