当我放大GUI窗口时,我希望所有小部件的长度(水平)都改变。现在,当我放大窗口时,只有行编辑会更改大小。最重要的是,我希望按钮和组合框更长。
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QGridLayout, QWidget, QListWidget, QLineEdit, QHBoxLayout, QPushButton
class Window(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
centralWidget = QWidget()
self.setCentralWidget(centralWidget)
self.Search_Bar = QLineEdit(placeholderText="Search")
self.Button = QPushButton('button')
layout = QHBoxLayout(centralWidget)
layout.addWidget(self.Button)
layout.addWidget(self.Search_Bar)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
答案 0 :(得分:1)
有2种可能的解决方案:
通过将小部件添加到布局中来设置相同的拉伸:
apple@Apples-MacBook-Pro ~ % npx @react-native-community/cli init --template=@react-native-firebase/template Fbsix
###### ######
### #### #### ###
## ### ### ##
## #### ##
## #### ##
## ## ## ##
## ### ### ##
## ######################## ##
###### ### ### ######
### ## ## ## ## ###
### ## ### #### ### ## ###
## #### ######## #### ##
## ### ########## ### ##
## #### ######## #### ##
### ## ### #### ### ## ###
### ## ## ## ## ###
###### ### ### ######
## ######################## ##
## ### ### ##
## ## ## ##
## #### ##
## #### ##
## ### ### ##
### #### #### ###
###### ######
Welcome to React Native!
Learn once, write anywhere
✔ Downloading template
✔ Copying template
✔ Processing template
⠙ Installing CocoaPods dependencies (this may take a few minutes)internal/modules/cjs/loader.js:796
throw err;
^
Error: Cannot find module '/Users/apple/Fbsix/ios/undefined'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
at Function.Module._load (internal/modules/cjs/loader.js:686:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
✖ Installing CocoaPods dependencies (this may take a few minutes)
error Error: Failed to install CocoaPods dependencies for iOS project, which is required by this template.
Please try again manually: "cd ./Fbsix/ios && pod install".
CocoaPods documentation: https://cocoapods.org/
在QSizePolicy::Expanding
按钮的水平组件上设置sizePolicy
:
layout.addWidget(self.Button, stretch=1)
layout.addWidget(self.Search_Bar, stretch=1)