Qt setgeometry не работает
Hi
My application is composed of widgets which are located in QStackedWidget(one at a time). QStackedWidget is set as the centralWidget of the QMainWindow;
In One of the Widget :MagazynGui I created QInputDialog as follows:
MagazynGui widget and QStackedWidget is created afterwards in QMainWindow(named DomGui).
So as we launch the program we see DomGui(QMainWindow) in which we have widget(QStackedWidget) and further we have MagazynGui(QWidget) in braces are Qt class names.
In MagazynGui form I have a push button and when I click on it I execute hereunder code.
. and unfortunetly I get this statement:
setGeometry: Unable to set geometry 120×30+1179+658 on QWidgetWindow/’QInputDialogClassWindow’. Resulting geometry: 178×90+1179+658 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 178×90, maximum size: 524287×90).
I have been trying to fix it but I can not to find any soluion. Maybe one of you has some idea how to solve the issue.
I can add that when I created a messagebox instead the inputDialog there was not any statement the like above mentioned.
Hi and welcome to devnet,
Can you share a minimal compilable sample application that chooses this behaviour ?
Hi
Thanks for welcome.
Hereunder there is a minimal compilable sample which creates the same statement:
setGeometry: Unable to set geometry 120×30+1180+655 on QWidgetWindow/’QInputDialogClassWindow’. Resulting geometry: 178×90+1180+655 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 178×90, maximum size: 524287×90).
//MainWindow.h
I see that it is not so easy.
Maybe «minimum size: 178×90, maximum size: 524287×90» got something to do with (both Y min and Y max are 90).
I have allready tried to change minimumSize() and maximumSize() as well. But it does not help.
What is weird here is that in my first soft(more complex) and in the second one (minimal compilable sample ) the two statements are the same in some of their parts, see:
The first one:
setGeometry: Unable to set geometry 120×30+1179+658 on QWidgetWindow/’QInputDialogClassWindow’. Resulting geometry: 178×90+1179+658 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 178×90, maximum size: 524287×90).
The second one:
setGeometry: Unable to set geometry 120×30+1179+658 on QWidgetWindow/’QInputDialogClassWindow’. Resulting geometry: 178×90+1179+658 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 178×90, maximum size: 524287×90).
The common parts are:
Resulting geometry: 178×90+1179+658 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 178×90, maximum size: 524287×90).
I was googling and found out that the problem could be caused by Windows but I am not sure.
My soft working properly but I try to get rid of the statement because it is annoying. You know a lot of red color is alarming
:-).
I can confirm that this warning don’t appear on Linux, with exactly the same code and with same Qt versions.
@Slawomir_Piernikowski try to pass ‘Qt::MSWindowsFixedSizeDialogHint’ window flag to ‘QInputDialog::getText’ method, it should remove the warning.
You have done it!. Great job.
Thanks.
Источник
Qt setgeometry не работает
I get the warning message: «setGeometry: Unable to set geometry 75×23+640+280 on QWidgetWindow/’QPushButtonClassWindow’. Resulting geometry: 124×23+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215×16777215).»
This happens with pretty much every widget. The program itself has no problem running. I’m running some tutorials from a book (written in 2007). The code is:
int main(int argc, char *argv[])
<
QApplication a(argc, argv);
What is the cause and how do I get rid of this message?
In the code , how r you using setGeometry() ??
That’s the thing. I’m not using it. The code sample I provided is the whole program.
[quote author=»ankursaxena» date=»1393408724″]In the code , how r you using setGeometry() ??[/quote]
Same problem here, even without line 11.
Up please ? :/
Information please. What Qt version? What platform? What compiler?
I am using Qt 5.1.2 32bit (with Qt Creator 3.0.1) on Windows 7 64bit. I don’t really know what compiler it is, it came with the MinGW installed with Qt. I used the online installer downloaded here : http://qt-project.org/downloads
So I guess it must be g++.
I was also using the MinGW compiler installed with Qt 5.1.2 64-bit..
I’m sure that book from 2007 is a good one, but it’s 7 years old, and things for sure have changed in Qt.
If you want it to run in Qt5 without it complaining about geometry, I’m guessing it nowadays needs a hint/default value for that. Maybe try by inserting one geometry call of your own. e.g.:
@ #include
#include
then it should run without messages 🙂
Gotta try that, didn’t even think about it. Thanks, I will give feedback 🙂
This example is a very old looking way to do it, though it will still work. The problem is the defualt values are going to be «junk» since there is no parent widget to place your button on. I think hskoglund suggestion will certainly fix your issue, but you will make a «floating» button attached to nothing 😮
You are probably better off starting with a Qt Widgets application example which you can create in Qt creator:
File —> New Project —> Application —> Qt Widgets application
Then you have a similar startup program, but this time you have a MainWindow on which to put your buttons.
So I tried hskoglund’s way, and it worked well, no warning this time 🙂
I’ll try code_fodder’s way when I’ll start another project with QtGUI.
Well done, remember to mark the post as solved by changing the title to
«[SOLVED] . title name. «
Источник
Why am I getting QWindowsWindow::setGeometry: Unable to set geometry warning with Qt 5.12.0
I migrated some code from Qt 5.6.0 to 5.12.0. Suprisingly, I’m getting lots of warnings related to QWindowsWindow::setGeometry . Whenever a dialog is shown on top of another, I get this warning.
I could isolate the problem in a MCVE, it’s very simple and minimal, all parenting look good, however, we get the warning when button is pressed:
I see the issue under Windows 7 and 10. Am I doing anything wrong?
I know the warning can be removed by setting setMinimumSize (see https://stackoverflow.com/a/31231069/3336423), but why should we do this for every widget we create? Is there a way to fix that for good?
2 Answers 2
As you mentioned, this problem occurs only in Windows: the QWindowsWindow class is part of the windows platform plugin. Looking at Qt’s source code ( qwindowswindow.cpp@QWindowsWindow::setGeometry ) there is no direct way to pause that specific message.
The only global solution I can think of right now is to filter the warning messages using a message handler:
UPDATE
One of the problems is that Windows adds its own buttons to the frame. In your example the dialog adds three buttons: the system button (the icon, top-left corner), the help button and the close button. The help and close buttons have a fixed size, which happens to be larger than the QDialog ‘s frame (which is computed as the maximum between the requested size and minimumSize ). This then generates the warning: your requested size doesn’t match the one created by Windows:
If you remove the help button, for example ( dlg.setWindowFlags(dlg.windowFlags() &
Qt::WindowContextHelpButtonHint); ), the warning disappears without setting a minimum size for the window. A manual action must be taken for each dialog displayed, but I think it is easier to automatize than the minimum size (through a factory maybe?):
Источник
Данный документ описывает как сохранить и восстановить геометрию окна используя свойства геометрии. В Windows решение данной задачи состоит в сохранении QWidget::geometry() и вызове QWidget::setGeometry() в следующей сессии перед вызовом show().
В X11 это не будет работать, так как неотображённое окно не имеет рамки. Оконный менеджер оформит окно позже. Когда это происходит, окно сдвигается к правому нижнему углу экрана, в зависимости от оформляющей рамки. Хотя X и предоставляет способ избежать этого перемещения, наши испытания показали, что некоторые оконные менеджеры не в состоянии реализовать данную возможность.
Начиная с 4.2, Qt обеспечивает функции, которые сохраняют и восстанавливают размеры и положение окон. QWidget::saveGeometry() сохраняет геометрию окна и полноэкранное или развёрнутое состояние, пока QWidget::restoreGeometry() не восстановит их. Функция восстановления также проверяет не выходит ли восстановленная геометрия за пределы геометрии окна и если это произошло, соответственно модифицирует её:
Если эти функции недоступны или не могут быть использованы, тогда решением будет вызов setGeometry() после show(). Это имеет два неудобства: на миллисекунды виджет отображается в неправильном положении (в результате эффект мерцания) и что в настоящий момент только каждый второй оконный менеджер может сделать это правильно. Более безопасное решение состоит в сохранении pos() и size() и восстановлении геометрии с помощью QWidget::resize() и move() перед вызовом show(), как показано в примере Application.
Источник
Custom QWidget: setGeometry не работает
Моя проблема в том, что self.spdBar.setGeometry не работает для импортированного виджета, пожалуйста, может кто-нибудь объяснить, что я делаю не так?
вот пользовательский виджет py файл:
Я предполагаю, что что-то не так в функции paintEvent.
EDIT: с этим кодом работает:
1 ответ
У меня возникла проблема с PyQt4. Я хочу создать новый виджет в окне, и я хочу, чтобы этот виджет имел собственный цвет. Когда я создаю подкласс класса QWidget и создаю его экземпляр, я не могу изменить его цвет фона с помощью функции setStyleSheet(). Когда я создаю экземпляр нового объекта.
Мое окружение таково: Qt 5.4, сборка из исходного кода с -platform win32-msvc2013 -opengl desktop -no-icu -skip webkit Visual Studio 2013 Windows 7 х64 Рассмотрим следующую настройку (a QScrollArea, содержащий центрированный виджет с фиксированным размером): QScrollArea scrollArea;.
Вы должны изменить следующее:
- Добавить parent к cPrg
- Если r = QtCore.QRect(15, 15, 300, 300) , то setGeometry(rect) должно быть больше.
Мое решение таково:
Похожие вопросы:
Почему? setGeometry: Unable to set geometry 22×22+320+145 on QWidgetWindow/’WidgetClassWindow’. Resulting geometry: 116×22+320+145 (frame: 8, 30, 8, 8, custom margin: 0, 0, 0, 0, minimum size.
Как установить ширину QWidget ? Я знаю функцию setGeometry(QRect& rect) , чтобы сделать это, но в этом случае я должен использовать функцию geometry() , чтобы получить прежние параметры моего.
У меня возникла проблема с PyQt4. Я хочу создать новый виджет в окне, и я хочу, чтобы этот виджет имел собственный цвет. Когда я создаю подкласс класса QWidget и создаю его экземпляр, я не могу.
Мое окружение таково: Qt 5.4, сборка из исходного кода с -platform win32-msvc2013 -opengl desktop -no-icu -skip webkit Visual Studio 2013 Windows 7 х64 Рассмотрим следующую настройку (a QScrollArea.
Итак, у меня есть этот QFrame , который является родительским виджетом (представленным this в коде). В этом виджете я хочу разместить QWidget на 10 пикселей сверху (и 10 пикселей снизу, в результате.
Я могу создать и увидеть QWidget в одной из функций класса главного окна: .. // ok QWidget *w = new QWidget(this); w->setGeometry(400,300,400,300); w->setStyleSheet(background-color:white;);.
У меня возникли проблемы с установкой размеров дочернего элемента-QWidget сразу после его добавления к родительскому-QWidget. Проблема в том, что он просто не задает геометрию: from PyQt4 import.
Цель состоит в том, чтобы нарисовать подкласс QWidget в другом QWidget. По дайте только координаты. #include #include #include int main(int argc.
Я хочу применить таблицу стилей к конкретному Qwidget , который я создаю в конструкторе родительского QWidget . Я не хочу создавать QWidget в конструкторе, но я хочу создавать его динамически. Это.
Источник