Im designing a Pyside Qt application and I want to toggle the QtCore.Qt.WindowStaysOnTopHint window flag in my main window. Setting this hint using this code works fine:
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.show()
but I can't work out how to remove a window flag using Pyside.
Does anybody know how to do this?
Window flags would normally be OR'd together with the existing flags:
print(int(self.windowFlags()))
self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
print(int(self.windowFlags()))
Then to remove the flag, AND it out using the flag's negation:
self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowStaysOnTopHint)
print(int(self.windowFlags()))
You can toggle the window's showing at the top or bottom like this:
def toggleFunc(self):
if self.someCheckedButton.isChecked(): #show up at the top
self.setWindowFlags(self.theMainWindow.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
else: #show up at the bottom
self.setWindowFlags(self.theMainWindow.windowFlags() & ~QtCore.Qt.WindowStaysOnTopHint)
self.show() #it's important to show up the window again after changing the window flags
Related
After many attempts and google searches I can't figure out how to set a button's background colour. This what I have right now.
password_button = Button(window, text="SUBMIT", width=5, command=click, bg="black").grid(row=2, column=0, sticky=W)
Any help would be appreciated.
There are some errors with your code. First of all, you should either make the button first and then grid it, or you can directly grid it. In your code, you are making a variable called password_button, but at the end of it, you are trying to grid the button from inside the variable. To solve the problem, you can just move the grid command to a separate line like this:
password_button = Button(window,
text="SUBMIT",
width=5,
bg="black")
password_button.grid(row=2, column=0,sticky=W)
Second of all, I don't think that changing background colors of buttons in tk is possible, but you can use ttk widgets to change the background color of a button.
My problem is only in Qtdesigner.
I am using QtDesigner v4.8.4 to define my HMI for a pyqt project. In this editor the window I have drown, has got a reduce and a close button in right up corner. I am sorry I wanted to show it to you with screenshots but I don't have enough reputation.
When I use it or previsualize it (with Ctrl + R), I lose the "minimize button" of the window and its functionnality.
Do you have the same behavior?
I have a useless ? button instead and the close button. How could I keep it to minimize my window ?
Thanks a lot for any advice!
When I use it or previsualize it (with Ctrl + R), I lose the "minimize button" of the window and its functionnality.
Answer : This is not bug, I just preview your widget only. If your implement in pyqt can see all button for windows.
Picture: Show previsualize of Qt4 Designer doesn't have "minimize button"
Picture: Show running of PyQt4 (It default have "minimize button")"
Can you please show an example of implementation of the minimize button of the up right corner because for my script
OK, Keyword is implement event in widget by this method QWidget.changeEvent (self, QEvent)
, Please see my example code, Hope is helps;
import sys
from PyQt4 import QtCore, QtGui, uic
(loadUserInterface, loadQWidget) = uic.loadUiType('QWelcomeWidget.ui')
class QWelcomeWidget (loadQWidget):
def __init__ (self, parent = None):
loadQWidget.__init__(self, parent)
self.ui = loadUserInterface()
self.ui.setupUi(self)
def changeEvent (self, eventQEvent):
if eventQEvent.type() == QtCore.QEvent.WindowStateChange:
if self.windowState() & QtCore.Qt.WindowMinimized:
print 'Window Minimized'
QtGui.QWidget.changeEvent(self, eventQEvent)
if __name__ == '__main__':
appQApplication = QtGui.QApplication(sys.argv)
mainQWidget = QWelcomeWidget()
mainQWidget.show()
# Start Application
sys.exit(appQApplication.exec_())
References : http://pyqt.sourceforge.net/Docs/PyQt4/qwidget.html#changeEvent
Regards,
convert your .ui file to (.py)python file using
pyuic4 filename.ui
sudo pyuic4 -x ptqt_filename.ui -o python_file_name.py
Now run that python file,you will be able to see all controls
python pyqt_first_ui.py
I have an application (menu bar) that, when running, puts itself at the top of my screen and everything else that loads, automatically knows to load below that menu bar. Its like the program established a new "top" of the screen and that top starts right below the menu bar. I want to duplicate this functionality in vb.net. Does anyone know how to accomplish this?
Basically, I'm looking for something to tell windows the top of the screen starts below my program. I hope that makes sense.
Thanks.
Check out the following project by Arik Poznanski
http://www.codeproject.com/Articles/3728/C-does-Shell-Part-3
Take this code, compile, and add it to your project as a reference. Then in the form load
Me.Edge = AppBarEdges.Top 'sets the form to dock at the top of the screen
This sets it to the top of the screen with everything else below.
This is similar to question 4799748, but I'd like to remove Windows borders from a QML application, so it starts up without minimise/maximise/close etc.
I guess I need to set the Window flags to Qt.CustomizeWindowHint, but I'm new to QML and can't see how to do that. The editor auto-completes the Qt.CustomizeWindowHint text, but I can't see how to apply that to the top level window.
Marko Frelih,
It's easy, just put flags: Qt.FramelessWindowHint inside your ApplicationWindow QML code
You need to set the Qt::FramelessWindowHint window flag. Since QDeclarativeView doesn't have a constructor accepting window flags you will have to set them after creating the view:
QDeclarativeView *viewer = new QDeclarativeView(0);
viewer->setWindowFlags(Qt::FramelessWindowHint);
viewer->setSource(QUrl::fromLocalFile("main.qml"));
viewer->show();
BTW, if you are using qmlviewer, you can pass -frameless to remove the border from its window.
Use flags: Qt.WindowFullScreen it works .
Other options:
flags : Qt::WindowFlags
I've got a small window that has no borders, titlebar, buttons, etc. I want to support full -screen mode (the new Lion kind) and I basically have all that working -- I can switch into and out of fullscreen mode and the window resizes itself, etc, no problems.
However, when I move the mouse to the top of the screen, the Menu bar with the icon to close the full screen mode does not slide down.
How do I get that working? Is it keyed off a style mask? Something else?
A-ha, the key is in what you return for
- (NSApplicationPresentationOptions)window: (NSWindow *)window willUseFullScreenPresentationOptions: (NSApplicationPresentationOptions)proposedOptions
You need to add NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationHideDock to the returned values in addition to NSApplicationPresentationFullScreen.
The only thing you need to do to make full screen mode work in Lion is to call ‑setCollectionBehavior: on your window and pass in NSWindowCollectionBehaviorFullScreenPrimary.
You don't need to do anything else. All the kiosk-mode stuff is not necessary unless you are targeting 10.6 or earlier.