Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to disable drag and drop and make window borderless
Forum Updated to NodeBB v4.3 + New Features

How to disable drag and drop and make window borderless

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lachdanan
    wrote on last edited by lachdanan
    #1

    Hi,

    So I am using a windows application that uses Qt, and there is a floating window which I want to modify.

    Basically I want to make this window borderless, transparent, and also ignore all keyboard and mouse events and disable all drag and drop also.

    The python interface is different than the standard qt so please ignore the differences.

    Before I was using this:
    mywidget.setWindowFlags(mywidget.windowFlags() | Qt.WindowTransparentForInput | Qt.FramelessWindowHint)

    and the window would immediately disappear. Now I sandwiched it between, mywidget.hide/show, and it works. Except it's not borderless, but at least the mouse events seem to be ignored.

    But the issue is click and drag is NOT ignored. I have a feeling that's because the window/widget has drag and drop feature. I called setAcceptDrops to False but still the same.

    So I am not sure how to make it work, or if it's because this window actually has many nested QtWidgets that I have to call the same function for all of them?

    Thanks so much in advance.

    Cheers,
    Yunus

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What version of Qt are you using ?
      On what OS ?
      You mention python, are you using PyQt5/PySide2 ?
      Can you provide a minimal example ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lachdanan
        wrote on last edited by lachdanan
        #3

        Hi,

        Thanks a lot :)

        I think it's qt5, windows 10.

        It's using PySide2.

        I can show you some codes. I kind of bypassed the drag issue by overlaying window B over A, vs A over B because A has the overlay issue.

        So now one of the next issues I ran into is, even though it seems to work, I am not able to bring the window back to front and remove the transparent for input flag.

        Is there a way to list the flags of a widget? I tried widget.windowFlags but it just prints an object, I would have liked to see which flags are stored there so I can set them manually when the user turns this transparency off. Storing them in memory will be a bit harder.

        As for code, this is the WIP code for now:

        from PySide2 import  QtCore, QtWidgets, QtGui
        from hutil.Qt import QtCore
        import time
        
        def setWindowToBG ( widget, state ):
            viewport.hide()
            widget.setAcceptDrops(not state)
            if state:
                widget.setWindowFlags(viewport.windowFlags() | QtCore.Qt.WindowTransparentForInput | QtCore.Qt.FramelessWindowHint)
            else:
                widget.setWindowFlags(QtCore.Qt.Window)
            widget.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents, state)
            widget.setAttribute(QtCore.Qt.WA_TranslucentBackground, state)
            widget.setDisabled(state)
            if state:
                widget.setWindowOpacity(0.5)
            else:
                widget.setWindowOpacity(0.8)
            viewport.show()
        
        
        enabled = hou.node(".").evalParm("enable")
        posx = 29
        posy = 119
        sizex = 2635
        sizey = 1767
        name = "animatrix network editor"
        
        a = hou.ui.mainQtWindow()
        app = QtGui.QGuiApplication.instance()
        
        viewport = None
        desktop = hou.ui.curDesktop()
        panels = desktop.floatingPanels()
        viewport = None
        for p in panels:
            if name in p.name():
                viewport = p
                
        allWidgets = app.allWidgets()
        for w in allWidgets:
            if name in w.windowTitle():
                viewport = w
                break;
        
        print "before", viewport
        print "desktop", desktop
        
        
        if viewport == None:
            panel = desktop.createFloatingPanel(hou.paneTabType.NetworkEditor)
            panel.setName(name)
            panel.paneTabs()[0].setPin(False)
            print "view created"
                
        
        
        allWidgets = app.allWidgets()
        for w in allWidgets:
            if name in w.windowTitle():
                viewport = w
                break;
                
        print "after creation", viewport
        
        if viewport:
            setWindowToBG ( viewport, enabled )
            viewport.showFullScreen()
            viewport.resize(sizex, sizey)
            viewport.move(posx, posy)
            for v in viewport.children():
                if v.isWidgetType():
                    viewport = v
            
            setWindowToBG ( viewport, enabled )
            
            for v in viewport.children():
                if v.isWidgetType():
                    viewport = v
            
            setWindowToBG ( viewport, enabled )
        

        Thanks a lot again,
        Yunus

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lachdanan
          wrote on last edited by
          #4

          Ok I figured out how to convert flags into int and then back to flags but not sure if it's working because all I want is to have the state of input transparency to be toggled ON and OFF, but it gets stuck in the ON state.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lachdanan
            wrote on last edited by
            #5

            Ok so I am closer to the result but there is still some weird behaviour.

            I now switch between states using this:

            def setWindowToBG ( widget, state ):
                #widget.hide()
                if state:
                    widget.setWindowFlags(viewport.windowFlags() | QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowTransparentForInput)
                else:
                    widget.setWindowFlags(viewport.windowFlags() | QtCore.Qt.FramelessWindowHint & ~QtCore.Qt.WindowTransparentForInput)
            
                #widget.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents, state)
                #widget.setAttribute(QtCore.Qt.WA_TranslucentBackground, state)
                #widget.setDisabled(False)
                if state:
                    widget.setWindowOpacity(0.05)
                else:
                    widget.setWindowOpacity(0.5)
                #widget.show()
            

            It works, but it flashes the entire screen. This is bad as I will perform this operation 100s of times while working. I tried a few different things and just now figured out that using FramelessWindowHint flag works. There is no more flash but now my top window is stuck in the BG, meaning it always have input transparency.

            I have set the widget to show fullscreen and then resized it. I feel this might be causing the issue but when I didnt do this, I couldn't get the window frame and title removed.

            Any ideas?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Glad you're on the right track !

              Can you explain what the role of this window is in your application ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lachdanan
                wrote on last edited by
                #7

                Hi, it's basically a control panel type of window. Btw is there a way to create transparency in a widget using a color? I need both actual opacity but also mask out the window by color. But it's not my widget so I don't have access to its code or paint events.

                So it has a background but it might not be the actual background qt supports.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  You can paint your widget background setting the Alpha channel of the color.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved