3

Is there a way I can use Qt Designer to design the Frame and the Title Bar ?

If so how can I make it work with existing code ?

Here is the existing code:

import sys

from PyQt5 import QtCore, uic
from PyQt5.QtWidgets import QApplication, QDialog


class Actions(QDialog):
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)

        self.ui = uic.loadUi("console_gui.ui")
        self.ui.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.ui.show()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = Actions()
    sys.exit(app.exec_())

If not, are there links to open source PyQt5 projects that successfully use FramelessWindowHint ?

PyQt5 has no documentation whatsoever on any of this. They just link to the C++ versions.

Vivek Joshy
  • 974
  • 14
  • 37

1 Answers1

0

You could use QPushButtons and QHBoxLayout.

class Actions(QDialog):
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)

        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)


        self.resize(500, 600)

        # 
        self.otherFrame = QFrame(self)

        # There are two Buttons and using them custom title bar.
        # We could give them string or pictures.
        self.oneButton = QPushButton('one')
        self.twoButton = QPushButton('two')

        # We must be give them some functions.
        self.oneButton.clicked.connect(self.oneClicked)
        self.twoButton.clicked.connect(self.twoClicked)

        # And some layouts.
        # This is a layout of horizontal.
        # 
        self.layouts = QHBoxLayout()
        # This is a layout of vertical.
        self.layouts2 = QVBoxLayout()

        self.layouts.addWidget(self.oneButton)
        self.layouts.addWidget(self.twoButton)
        self.layouts.addStretch(1)

        self.layouts2.addLayout(self.layouts)
        self.layouts2.addWidget(self.otherFrame)


        self.setLayout(self.layouts2)

        self.show()

    def oneClicked(self):
        print(1)

    def twoClicked(self):
        print(2)



    def mousePressEvent(self, event):

        if event.buttons() == Qt.LeftButton:
            self.m_drag = True
            self.m_DragPosition = event.globalPos()-self.pos()
            event.accept()

    def mouseMoveEvent(self, event):
        try:
            if event.buttons() and Qt.LeftButton:
                self.move(event.globalPos()-self.m_DragPosition)
                event.accept()
        except AttributeError:
            pass

    def mouseReleaseEvent(self, event):
        self.m_drag = False

Like this.

enter image description here

Cyrbuzz
  • 119
  • 1
  • 8