So I am trying to create a window (QDialog) with a width of a 100% (of the screen) and a height of a fixed value, eg. 60px.
I tried to achieve this by setting the maximumSize's height property to 60px, leaving the width to whatever it was. (16777215) I also set the horizontal sizePolicy to Maximum, and the vertical to Fixed, with stretch values of 1 and 0 respectively.
As you can see in the picture above, the dialog appears centered, but not stretched at all horizontally.
The code is pretty simple as seen below, its just a frameless QDialog:
from PyQt5 import QtWidgets, QtCore, uic
import sys
import os
class FMenu(QtWidgets.QDialog):
def __init__(self):
super(FMenu, self).__init__()
os.chdir(os.path.dirname(__file__))
self.ui = uic.loadUi('./ui/ui_searchbar.ui', self)
self.ui.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.ui.show()
app = QtWidgets.QApplication(sys.argv)
window = FMenu()
app.exec_()
The ui file I created with QtDesigner is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SearchBar</class>
<widget class="QDialog" name="SearchBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>60</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>60</height>
</size>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="styleSheet">
<string notr="true">background: #2b2b2b;</string>
</property>
<widget class="QWidget" name="centralwidget" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>801</width>
<height>61</height>
</rect>
</property>
<widget class="QLineEdit" name="lineEdit_searchBar">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>781</width>
<height>41</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>41</height>
</size>
</property>
<property name="font">
<font>
<family>Times New Roman</family>
<pointsize>22</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background: #3b3b3b;
color: #fff;</string>
</property>
<property name="placeholderText">
<string>Write here...</string>
</property>
</widget>
</widget>
</widget>
<resources/>
<connections/>
</ui>
What am I missing?