Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8859937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:10:07+00:00 2026-06-14T15:10:07+00:00

Using PyQt4, when I hide a window and show it afterwards, it appears at

  • 0

Using PyQt4, when I hide a window and show it afterwards, it appears at another position (at least here on Linux). Example code:

#!/usr/bin/python3

from PyQt4.QtGui import *

app = QApplication([])
widget = QWidget()
widget.setLayout(QVBoxLayout())
label = QLabel()
widget.layout().addWidget(label)

def hideShow():
    widget.hide()
    widget.show()

widget.layout().addWidget(QPushButton('Hide/Show', clicked = hideShow))
widget.show()
app.exec_()

The window disappears and appears, but a bit below and to the right of the original position. I think it’s displaced by the size of the window manager’s frame around the actual widget.

How can I place the window at the exact position where it was? And why does it move at all? Shouldn’t it stay where it is?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:10:08+00:00Added an answer on June 14, 2026 at 3:10 pm

    On Linux, window placement can be very unpredictable. See this section in the Qt documentation for a break-down of the issues.

    There’s probably no general solution to the problem, but for me, setting the geometry before the initial show() seems to work:

    ...
    widget.setGeometry(200, 200, 100, 50)
    widget.show()
    app.exec_()
    

    UPDATE

    After some testing with the KDE window manager, I may have discovered a potential solution.

    It seems that calling show() immediately after hide() does not give the window manager enough time to calculate the correct window position. So a simple workaround is to explicitly set the geometry after a small delay:

    from PyQt4.QtGui import *
    from PyQt4.QtCore import QTimer
    
    app = QApplication([])
    widget = QWidget()
    widget.setLayout(QVBoxLayout())
    label = QLabel()
    widget.layout().addWidget(label)
    
    def hideShow():
        widget.hide()
        QTimer.singleShot(25, showWidget)
    
    def showWidget():
        widget.setGeometry(widget.geometry())
        widget.show()
    
    widget.layout().addWidget(QPushButton('Hide/Show', clicked = hideShow))
    widget.show()
    app.exec_()
    

    This works for me using KDE-4.8 and OpenBox, but of course YMMV.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just a simple question: I'm using pyqt4 to render a simple window. Here's the
I'm developing a plugin UI for an existing application using PyQt4. The window is
With Qt4 (here using PyQt4) to get the area of intersection of two QWidgets---and
Using PyQt4 4.8.6 the code below produces the error QObject::startTimer: QTimer can only be
I have some code creating a QTabWidget from Python using PyQt4. I want to
Trying to build a user interface using PyQt4. Got a dialog window that pops
I'm creating a User Interface using PyQt4 module . the problem i'am facing is
I am working on python plugins.I designed my form using pyqt4 designer. I used
I am making a music player in PyQt4, and I am using Phonon to
I am trying the following in PyQt4, using SQLAlchemy as the backend for a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.