How to get coordinates of QToolBar icons in PyQt4 application? - python

I'd like to know how to set position of QCalendarWidget just below the button of ToolBar.
Currently, when user clicks a icon button inside red box,
then the below Calendar() instance is created and the instance is shown in the middle of screen.
What I want to implement is like the following.
You can refer full source code from here.
Any suggestion or advice will be appreciated.

This functionality is already provided by QDateTimeEdit, so you don't need a separate button for it:
def init_toolbar(self):
...
dtedit = QtGui.QDateTimeEdit()
dtedit.setCalendarPopup(True)
Qt Docs: QDateTimeEdit.setCalendarPopup.

This is usually done with a combination of using QWidget.geometry() or QWidget.rect() to get the size and position of a widget (in this case, the clicked button) and then using the QWidget.mapFromXXX and QWidget.mapToXXX series of functions, to transform those into global coordinates and then into widget coordinates that can be fed to QWidget.move()

Related

wxpython treectrl show bitmap picture on hover

So i'm programming python program that uses wxPython for UI, with wx.TreeCtrl widget for selecting pictures(.png) on selected directory. I would like to add hover on treectrl item that works like tooltip, but instead of text it shows bitmap picture.
Is there something that already allows this, or would i have to create something with wxWidgets?
I am not too familiar with wxWidgets, so if i have to create something like that how hard would it be, lot of code is already using the treectrl, so it needs to be able to work same way.
So how would i have to go about doing this? And if there might be something i might be missing id be happy to know.
Take a look at the wx.lib.agw.supertooltip module. It should help you to create a tooltip-like window that displays custom rich content.
As for triggering the display of the tooltip, you can catch mouse events for the tree widget (be sure to call Skip so the tree widget can see the events too) and reset a timer each time the mouse moves. If the timer expires because the mouse hasn't been moved in that long then you can use tree.HitTest to find the item that the cursor is on and then show the appropriate image for that item.

wxpython: dynamically created buttons are disabled

I want to create buttons dynamically
self.ctset = wx.BitmapButton(panel, -1, self.pic1, pos=(10,10), size=(50,50))
self.ctset.Bind(wx.EVT_BUTTON, self.add_ct)
self.ctset.SetDefault()
and the add_ct binding function
def add_ct(self, event):
pos=(10,self.yct)
self.yct+=65
self.new = wx.BitmapButton(self, -1, self.pic1, pos=pos,size=(50,50))
self.new.SetDefault()
print "Cutset"
I don't know where I am going wrong but my dynamically created buttons always seem disabled!
I want to bind a function to the dynamically created buttons that allows me to drag them around. Any ideas would be of great help!
I am pretty new to python and wxpython.
I don't see any code that captures the mouse's coordinates or even any drag-and-drop code. You need to download the wxPython demo package from the wxPython website and look at the ShapedWindow example for catching mouse coordinates. See also this old thread: http://wxpython-users.1045709.n5.nabble.com/Drag-Button-around-a-Panel-td3358640.html
In it you will find someone who is doing something very similar to what you want. I also found the following links which you might find helpful:
Drag button between panels in wxPython
How to move items smoothly in wxPython?

Qt - Temporarily disable all events or window functionality?

I have a Qt program with many buttons, user-interactable widgets, etc.
At one stage in the program, I would like all the widgets to temporarily 'stop working'; stop behaving to mouse clicks and instead pass the event on to one function.
(This is so the User can select a widget to perform meta operations. Part explanation here: Get variable name of Qt Widget (for use in Stylesheet)? )
The User would pick a widget (to do stuff with) by clicking it, and of course clicking a button must not cause the button's bound function to run.
What is the correct (most abstracted, sensible) method of doing this?
(which doesn't involve too much new code. ie; not subclassing every widget)
Is there anything in Qt designed for this?
So far, I am able to retrieve a list of all the widgets in the program (by calling
QObject.findChildren(QtGui.QWidget)
so the solution can incorporate this.
My current horrible ideas are;
Some how dealing with all the applications events all the time in one
function and not letting through the events when I need the
application to be dormant.
When I need dormancy, make a new transparent widget which recieves
mouse clicks and stretch it over the entire window. Take coordinates
of click and figure out the widget underneath.
Somehow create a new 'shell' instance of the window.
THANKS!
(Sorry for the terrible write-up; in a slight rush)
python 2.7.2
PyQt4
Windows 7
You can intercept events send to specific widgets with QObject::installEventFilter.
graphite answered this one first so give credit where credit is due.
For an actual example in PySide, here's an example you might draw some useful code from:
my_app.py
from KeyPressEater import KeyPressEater
if __name__ == "__main__":
app = QApplication(sys.argv)
eater = KeyPressEater()
app.installEventFilter(eater)
KeyPressEater.py
class KeyPressEater(QObject):
# subclassing for eventFilter
def eventFilter(self, obj, event):
if self.ignore_input:
# swallow events
pass
else:
# bubble events
return QObject.eventFilter(self,obj,event)

What's the suitable widget in PyQt to create a floating widget on the desktop?

I'd like to create something very alike to Rainlendar with python.
Currently I'm using PyQt for GUI, but there doesn't seem to be a widget type that can directly display something like that, specifically I mean:
No edge displayed, incuding buttons on the top right corner.
No corresponding bar in the task bar.
Able to display a icon in the icon area in the bottom right corner of the desktop.
Is there any widget capable of this ?
Or can I do some modification to any existing widget to achieve this ?
Thanks.
Have a look at the docs for QWidget.setWindowFlags. In particular, when coupled with Qt.FramelessWindowHint it should be borderless and buttonless.
Another task for setWindowFlags — setting it to Qt.Tool stops the task bar entry. So combined with the above, you want window.setWindowFlags(Qt.Tool | Qt.FramelessWindowHint)
See the docs for QSystemTrayIcon

How do I get rid of the arrow in a Tix.Balloon widget?

When I use the standard Tix.Balloon widget, bind it to a button and use a balloonmsg, I get the tooltip over the button, but I also get a stupid looking arrow inside the tooltip. (See the demo code from the Python source tree here.) Is it possible to get rid of this arrow, or do I need to use another type of widget to get a normal looking tooltip?
This will set the arrow image to a blank bitmap
b = Tix.Balloon(root)
b.subwidget('label')['image'] = Tkinter.BitmapImage()
There are two subwidgets within a balloon, label which is the arrow and message which is the text.
I'm still new to python so there might be a better way to actually remove the arrow instead of just cover it up.
I am using Python 3.2

Categories

Resources