1

Дизайнером не пользуюсь, пишу код сам. Так вот: Надо, что бы QTextEdit был по размеру окна и не закрывал ни statusbar, ни menubar. Когда меняешь размер окна, QTextEdit меняет размер тоже.

Если, я просто установлю размер и передвину QTextEdit, куда надо, то при изменении размера окна QTextEdit не изменится.

# -*- coding: utf-8 -*-

import os
import sys
from PyQt5 import(QtWidgets, QtGui, QtCore)

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()

        self.main()

    def main(self):
        self.setWindowTitle("PlainNote")
        self.setWindowIcon(QtGui.QIcon("img/ico.png"))

        self.resize(560, 315)
        self.move(300, 300)

        exitAction = QtWidgets.QAction("&Exit", self)
        exitAction.setShortcut("Ctrl+Q")
        exitAction.setStatusTip("Close the app")
        exitAction.triggered.connect(QtWidgets.qApp.quit)

        newFileAction = QtWidgets.QAction("&New file", self)
        newFileAction.setShortcut("Ctrl+N")
        newFileAction.setStatusTip("Create new file")
#        newFileAction.triggered.connect()

        saveAction = QtWidgets.QAction("&Save", self)
        saveAction.setShortcut("Ctrl+S")
        saveAction.setStatusTip("Save file")
#        saveAction.triggered.connect()

        saveAsAction = QtWidgets.QAction("&Save as...", self)
        saveAsAction.setStatusTip("Save file as...")
#        saveAsAction.triggered.connect()

        openAction = QtWidgets.QAction("&Open...", self)
        openAction.setShortcut("Ctrl+O")
        openAction.setStatusTip("Open file...")
#        openAction.triggered.connect()

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(newFileAction)
        fileMenu.addAction(saveAction)
        fileMenu.addAction(saveAsAction)
        fileMenu.addAction(openAction)
        fileMenu.addAction(exitAction)

        self.textBlock = QtWidgets.QTextEdit(self)
        self.textBlock.setWordWrapMode(False)

        self.statusBar().showMessage("...")

def start():
    app = QtWidgets.QApplication(sys.argv)
    window = MainWindow()
    window.show()
    app.exec_()

if __name__ == "__main__":
    start()

1 ответ 1

1

Установите self.textBlock как self.setCentralWidget(self.textBlock)

Подробнее читаем здесь https://doc.qt.io/qt-5/qmainwindow.html#qt-main-window-framework

import os
import sys
from PyQt5 import(QtWidgets, QtGui, QtCore)

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()

        self.main()

    def main(self):
        self.setWindowTitle("PlainNote")
        self.setWindowIcon(QtGui.QIcon("img/ico.png"))

        self.resize(560, 315)
#        self.move(300, 300)

        exitAction = QtWidgets.QAction("&Exit", self)
        exitAction.setShortcut("Ctrl+Q")
        exitAction.setStatusTip("Close the app")
        exitAction.triggered.connect(QtWidgets.qApp.quit)

        newFileAction = QtWidgets.QAction("&New file", self)
        newFileAction.setShortcut("Ctrl+N")
        newFileAction.setStatusTip("Create new file")
#        newFileAction.triggered.connect()

        saveAction = QtWidgets.QAction("&Save", self)
        saveAction.setShortcut("Ctrl+S")
        saveAction.setStatusTip("Save file")
#        saveAction.triggered.connect()

        saveAsAction = QtWidgets.QAction("&Save as...", self)
        saveAsAction.setStatusTip("Save file as...")
#        saveAsAction.triggered.connect()

        openAction = QtWidgets.QAction("&Open...", self)
        openAction.setShortcut("Ctrl+O")
        openAction.setStatusTip("Open file...")
#        openAction.triggered.connect()

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(newFileAction)
        fileMenu.addAction(saveAction)
        fileMenu.addAction(saveAsAction)
        fileMenu.addAction(openAction)
        fileMenu.addAction(exitAction)

        self.textBlock = QtWidgets.QTextEdit(self)
        self.textBlock.setWordWrapMode(False)

        self.statusBar().showMessage("...")
        
        self.setCentralWidget(self.textBlock)             # +++

def start():
    app = QtWidgets.QApplication(sys.argv)
    window = MainWindow()
    window.show()
    app.exec_()

if __name__ == "__main__":
    start()

введите сюда описание изображения

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.