[PyQt] rotateing QInputDialog

David Boddie david at boddie.org.uk
Sat Nov 22 20:18:44 GMT 2008


On Sat Nov 22 08:09:59 GMT 2008, Oguz Yarimtepe wrote:

> Is there any way like resizing or setting geometry for QInputDialog for
> rotating it or should i create a rotatable widget including QInputDialog
> and rotate it?

I'm guessing that you want to do this in a graphics scene. Is that correct?

This could prove to be difficult, given that QInputDialog only provides
static methods, but it seems to be possible to do something that works.

I started a new interpreter session and typed the following:

  from PyQt4.QtGui import *
  app = QApplication([])
  gs = QGraphicsScene()
  gv = QGraphicsView()
  gv.setScene(gs)
  gv.show()

This sets up a graphics view and a scene we can use. The static methods
for QInputDialog accept a widget to use for the dialog's parent, so we
create this and add it to the scene:

  w = QWidget()
  w.setWindowOpacity(0)
  pw = gs.addWidget(w)

We also make it invisible because we don't want to actually see it; we only
need it to get QInputDialog into the scene.

Just for fun, we rotate the proxy widget returned by the addWidget() call
to the scene, and we call the dialog's getText() method with the original
widget as the parent widget:

  pw.rotate(45)
  result, valid = QInputDialog.getText(w, "Input Text", "Value:")

Note that we can't use a QGraphicsWidget as the parent widget because it
isn't actually a subclass of QWidget. A rotated dialog should appear in
the view.

David


More information about the PyQt mailing list