apply dragEnterEvent and dragLeaveEvent on a QFrame

0

I would like to know how I can use the dragEnterEvent event and dropEvent of a QFRame to be able to apply a resize effect on a QFrame.

that is to say when positioning the mouse inside the frame it would have a width of 100 and when leaving a with of 50

this is what I tried:

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


class Principal(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        uic.loadUi("nuevo.ui",self)

        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.bmax.clicked.connect(self.showNormal)
        self.bmin.clicked.connect(self.showMinimized)


    def dragEnterEvent(self,obj,event):
        if event == self.mouseMoveEvent:
            if obj == self.contenedor:
                print("contenedor selecionado")
                self.contenedor.width(100)
    def dragLeaveEvent(self,obj,event):
        if event == self.mouseMoveEvent:
            if obj == self.contenedor:
                print("contenedor no selecionado")
                self.contenedor.width(50)


app = QApplication([])
p = Principal()
p.show()
app.exec_()

nuevo.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>908</width>
            <height>515</height>
           </rect>
          </property>
          <property name="windowTitle">
           <string>MainWindow</string>
          </property>
          <widget class="QWidget" name="centralwidget">
           <widget class="QFrame" name="contenedor">
            <property name="geometry">
             <rect>
              <x>0</x>
              <y>-10</y>
              <width>151</width>
              <height>551</height>
             </rect>
            </property>
            <property name="styleSheet">
             <string notr="true">QFrame#contenedor{
        background:#042944;
        }</string>
            </property>
            <property name="frameShape">
             <enum>QFrame::StyledPanel</enum>
            </property>
            <property name="frameShadow">
             <enum>QFrame::Raised</enum>
            </property>
           </widget>
           <widget class="QFrame" name="frame">
            <property name="geometry">
             <rect>
              <x>0</x>
              <y>0</y>
              <width>921</width>
              <height>41</height>
             </rect>
            </property>
            <property name="styleSheet">
             <string notr="true">background:#0F5D8D;</string>
            </property>
            <property name="frameShape">
             <enum>QFrame::StyledPanel</enum>
            </property>
            <property name="frameShadow">
             <enum>QFrame::Raised</enum>
            </property>
            <widget class="QPushButton" name="bmin">
             <property name="geometry">
              <rect>
               <x>870</x>
               <y>10</y>
               <width>31</width>
               <height>23</height>
              </rect>
             </property>
             <property name="styleSheet">
              <string notr="true">background:none;
        border:0px;</string>
             </property>
             <property name="text">
              <string/>
             </property>
             <property name="icon">
              <iconset>
               <normaloff>boton-eliminar-con-linea-horizontal.png</normaloff>boton-eliminar-con-linea-horizontal.png</iconset>
             </property>
            </widget>
            <widget class="QPushButton" name="bmax">
             <property name="geometry">
              <rect>
               <x>820</x>
               <y>10</y>
               <width>31</width>
               <height>23</height>
              </rect>
             </property>
             <property name="styleSheet">
              <string notr="true">background:none;
        border:0px;</string>
             </property>
             <property name="text">
              <string/>
             </property>
             <property name="icon">
              <iconset>
               <normaloff>multi-tab.png</normaloff>multi-tab.png</iconset>
             </property>
            </widget>
           </widget>
          </widget>
         </widget>
         <resources/>
         <connections/>
        </ui>
    
asked by Revsky01 05.12.2018 в 02:34
source

0 answers