I am creating an UI for my application using QT. When I change size of my window some of labels are gets cropped.
So what I've tried is
ui.setupUi(this);
QWidget::showMaximized();
ui.statusBar->setSizeGripEnabled(false);
int w = QWidget::width()/10;
int h = QWidget::height()/10;
then using this values I've resize my labels.
However it doesn't work while my software is open and it is not a goodway to do it I think. So I have to dynamically change label sizes in order to keep all items in the window
I've been searching days and days to figure out but still I have no clue.
this is the gui I've created.
and when I change size.
Read up on Layout Management in Qt.
Related
Today I switched the font of my application from one of the standard system fonts to Sinkin in the form of an otf file, I've added to my resource.qrc.
The following code sets the default font of the application object.
int id = QFontDatabase::addApplicationFont(":/fonts/font.otf");
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
qapp.setFont(family);
QFont font = qapp.font();
font.setPointSize(opt_font_size);
qapp.setFont(font);
Now it seems, that the font is placed a bit too high in all elements. That means buttons, labels, input fields and tabs. Or Qt does not realize, that it has to adjust the size of the elements to fit the new font.
Changing the font size via setPointSize does not fix it. Everything just gets smaller or bigger.
Any ideas where I can dig into?
I currently set a QDialog to have a fixed size using the following code
dlg->setWindowModality(Qt::WindowModal);
dlg->setFixedSize(dlg->size());
Now as a result of this code whatever size I save my ui form in QT Designer. It sticks to that size.This however ends up being a issue in some systems and displays. Where my Qlabels begin to cut from the sides due to the shortage of space.I wanted to know what would be the proper way of doing this ? How would I determine which size would accommodate the layout on the form.The form itself has a horizontal layout which has multiple layouts in it ??
Try
dlg->adjustSize();
dlg->setFixedSize(dlg->sizeHint());
I'm wondering if there is a way to make Qt widgets within a QMainWindow widget stretch and scale as the size of the main window is stretched and shrunk. Basically, I'd like the entire window and it's contents to have the same appearance except for size:
At the only way I can think to accomplish this is to get the size of the main window, do the math for every single widget, and reset their sizes any time the main window size is changed, but I'm thinking there's an easier way.
I like this video tutorial on youtube. I'll help you create a layout using QLayout classes. If you use QtCreator/Designer, you can also take a look at the auto-generated ui_MainWindow.XXX file that will clue you in on how it uses some of the UI classes.
As always, QtCreator/Designer has a bunch of hints and tips so you should be able to dig up from the documentation that's embedded in the application.
I have developed my Application with most of the Widgets in Qt Creator's Designer module.
I have hard coded the sizes of my widgets depending on how they appeared on my laptop. Yesterday when I ran the application on my Desktop (lower screen resolution than laptop) some of the Main Window widgets were not visible & on startup there was horizontal scrollbar & I had to scroll to see those widgets; which is not the case on my laptop.
I have 2 problems:
Is it possible to resize all of my widgets (even those which are added run time by code) by using some resize factor? Maybe at startup I will get the screen resolution of Hardware in which application is running & then create a ratio of that with resolution of my laptop. Is it possible to multiply this factor to all widgets without adding code for each widget?
How do I get the resolution of the Screen in which my Application is running?
PS: I would like to know the defacto method of solving this problem...
Thank You.
You could try a function like this:
resize(theDesktop->screenGeometry().width()*PERCENTAGE_OF_MONITOR_WIDTH_FOR_SCREEN, theDesktop->screenGeometry().height()*PERCENTAGE_OF_MONITOR_HEIGHT_FOR_SCREEN);
Resize is a member function of the QWidget class and the PERCENTAGE_OF_MONITOR variables would be whatever percentage of the monitor you want your application to take up.
theDesktop is of the type QDesktopWidget.
You should use Layouts to manage the size policy of your widgets.
Qt layouts automatically position and resize widgets when the amount of space
available for them changes, ensuring that they are consistently
arranged and that the user interface as a whole remains usable."
You could also check this question for more information regarding layout machanisms in Qt.
Qt website has got excelent documentation on the subject. You can start here for more information on working with layouts in Qt Designer.
I want to resize the frame window in a SDI application to a given dimension of the child view window (I want the frame to fit the dimensions of an image). Can anyone describe an (elegant) solution to finding the relation between the child view client size and the frame window size without actually resizing the window?
Currently I am using GetParentFrame()->MoveWindow(,,,) to resize the frame window. I already tried to observe the difference between GetParentWindow()->GetClientRect() and GetParentWindow()->GetWindowRect() but it does not help.
Have a look at CWnd::CalcWindowRect. It computes the size of the window required to hold a given client area. I've never used it so I don't know how it deals with toolbars, etc. but I think it can be a good starting point.