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. Unable to set geometry, when Widget is moved after it is shown
Forum Updated to NodeBB v4.3 + New Features

Unable to set geometry, when Widget is moved after it is shown

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 181 Views
  • 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.
  • J Offline
    J Offline
    JoelRR
    wrote on last edited by
    #1

    Hello everyone, I have next situation. I'm using QFileSystemWatcher to determine when the directory content has changed. If it has, then I allocate a widget of fixed size (400x400) and display it. The problem is, when I command to show the widget and afterwards I try to move the widget to the center of the screen I get next runtime message and widget is not displayed with the correct size:

    setGeometry: Unable to set geometry 400x400+761+348 (frame: 422x456+750+303) on QWidgetWindow/"QWidgetClassWindow" on "\.\DISPLAY1". Resulting geometry: 602x603+764+362 (frame: 624x659+753+317) margins: 11, 45, 11, 11 minimum size: 400x400 maximum size: 400x400 MINMAXINFO maxSize=0,0 maxpos=0,0 mintrack=422,456 maxtrack=422,456)

    This behavior is not observed if widget is allocated out of the slot called when the directory content changes.

    Next code shows a minimal example of what I'm talking about. The solution to this is to first set the geometry of the widget and then display it (in case someone faces the same problem).

    MainWindow::MainWindow(int argc,char **argv)
        : QApplication(argc, argv)
    {
        QFileSystemWatcher* sysWatcher = new QFileSystemWatcher(this);
        sysWatcher->addPath("C:\\PrintMe");
    
        connect(sysWatcher,SIGNAL(directoryChanged(QString)), this,SLOT(allocateWidget()));
    
        // If widget is allocated out of slot there is no issue
        allocateWidget();
    }
    
    void MainWindow::allocateWidget()
    {
        QWidget *w = new QWidget(0);
        w->setFixedSize(400, 400);
    
        w->show();
    
        QRect g = QApplication::screens()[0]->availableGeometry();
        w->move(g.center() - w->rect().center());
    }
    

    I got the solution by coincidence but I wonder if someone has an explanation for this behavior. I'm using Qt 5.15.2 and MinGW compiler.

    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