Why QSpinBox get focus when focusPolicy = NoFocus - qt

Why QSpinBox receives focus at pressed Shift + Tab? How to fix?
Example:
Create a form as in picture 1.
Set spinBox_2 and pushButton_2 focusPolicy = NoFocus
Start, and try to press Tab several times, and to press Shift+Tab.
We see that spinBox_2 get focus.
OC: windows 10. Qt 5.12.3.
in *.ui file
mainwindow.ui
<widget class="QSpinBox" name="spinBox_2">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pushButton_2">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>

To answer your question "Why?", it's because it is a bug.
If you have time you can file a bug: https://bugreports.qt.io/

Tried to set the tab order to not to letting spinBox_2 selected?
See Qt Designer's Tab Order Editing Mode

Related

My custom widget is not shown in Qt Creator / Qt Designer but it is shown when I execute the program

I would like to have a QTabWidget with a tab containing a custom widget.
I created a custom Widget (consisting of a .ui, .h and .cpp file)
I added this custom Widget to the first page of my QTabWidget, but the content of this Widget is not shown in QtCreator's designer.
I promoted my custom Widget as Tab1Custom.
This setup compiles and works as expected when I run the program, but my custom control doesn't show up in QtCreator's designer.
What can I do to make my custom control show up in QtCreator's designer?
Here's the first part of MainWindow.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>my title </string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>10</y>
<width>801</width>
<height>551</height>
</rect>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="Tab1Custom" name="myTab1">
<attribute name="title">
<string>My Tab number 1</string>
</attribute>
</widget>
....
This is how it works when you use a custom widget and promote it. In order to have your widget drawn with content, you have to create a DLL to extend Qt Designer. Look at "Creating Custom Widgets for Qt Designer" for more information on that.
For the most part, I don't think it's worth the effort to do this; generally speaking, it's fine that it just shows a either a blank widget or whatever base widget you promoted.

QT5 Title bar obscures top row of buttons on Windows 10

My PyQT5 application is working fine on Linux, macOS and some Windows PCs, but on some Windows 10 PCs the top row of buttons is obscured by the window frame / title bar:
Not only are the buttons obscured, you have to click below the buttons in order to click on them, so the click locations appear to be correct but the buttons are shown above the click locations.
The buttons are created in a QT Creator UI file as follows:
<widget class="QMainWindow" name="MainWindow">
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="10">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="OpenButton">
Versions: PyQt 5.6.0, qt5.6.2 from Miniconda
As indicated by #Arpegius, this turns out to be due to the Intel Graphics Driver (see QT bug 62127.
The problem disappears if I configure the QT application to use my NVidia adapter instead of my Intel adapter.

Qt button take as much space as the text on it needs

I have a button in Qt Designer and I want it to take always as much space as the text on it needs. How can i accomplish that?
I mean like the text on the button is "Hello" and the button will be 45px.
When I do self.button.setText("Hello World") the button will be 85px.
My current "servers.ui":
<item>
<widget class="QPushButton" name="pageLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
I'm actually talking about:
Use a QToolButton instead of a QPushButton and clear its maximum size.
You may need to set the vertical size-policy to "Preferred" so that it to has the same height as the other buttons. To get a flat button, check the "autoRaise" property.
A quick way to change the button class is to right-click it and select "Morph Into" from the context menu.

Creating a Web Form from an XML Description of It

i am assigned to web part of some project.My duty is to create web form from xml.
These xml comes from window part and tells which controls are include in my web form and their properties.My xml Format is like below.
<Object type="System.Windows.Forms.Form">
<Property name="Name">Form1</Property>
<Property name="Text">Option</Property>
<Object type="System.Windows.Forms.RadioButton">
<Property name="Name">RadioButton1</Property>
<Property name="Size">86, 24</Property>
<Property name="Text">RadioButton1</Property>
<Property name="Location">175, 126</Property>
</Object>
<Object type="System.Windows.Forms.CheckBox">
<Property name="Name">CheckBox1</Property>
<Property name="Size">84, 24</Property>
<Property name="Text">Accept</Property>
<Property name="Location">84, 126</Property>
</Object>
<Object type="System.Windows.Forms.TextBox">
<Property name="Name">TextBox1</Property>
<Property name="Size">177, 20</Property> 1
<Property name="Text">Singapore</Property>
<Property name="Location">84, 88</Property>
</Object>
<Object type="System.Windows.Forms.Label">
<Property name="Name">Label1</Property>
<Property name="Size">100, 23</Property>
<Property name="Text">Name</Property>
<Property name="Location">7, 53</Property>
</Object>
<DataSet1>
<Table1>
<TableName>TableOne</TableName>
<ItemName>item001</ItemName>
<Qty>100</Qty>
<Price>1000</Price>
</Table1>
<Table2>
<TableName>TableTwo</TableName>
<ItemName>item002</ItemName>
<Qty>200</Qty>
<Price>2000</Price>
</Table2>
</DataSet1>
</Object>
what is the best way to solve my problem? i found some people used
XmlSerialization, so, can i use this way or is there any other way?
I hope you don't expect to be adding Windows Forms controls onto your web form.
This doesn't make much sense. You will not only need to create a web form - you also need to be able to create code to handle events from the controls on the form. I don't see anything in your XML that describes that.

Qt manually change the ratio between items in layout

I have two QTreeViews in a QHBoxLayout.
<layout class="QHBoxLayout" name="lay_disk_content">
<item>
<widget class="QTreeView" name="lay_disk_tvA">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="lay_disk_tvB">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
</layout>
When I resize the QMainWindow the two QTreeViews get resized with an 1:1 ratio between them. Now I would like to manually change it in the running program through dragging the space between them. This is somewhat a standard behavior but I don't get the name of it.
QSplitter

Resources