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. [SOLVED] centering a dialog to the screen is not working

[SOLVED] centering a dialog to the screen is not working

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.7k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    kalster
    wrote on last edited by
    #1

    I am trying to center the dialog form on the screen. when i put the below code into the mainwindow.cpp file i get an error. what am i doing wrong?

    @void centerWidgetOnScreen (QWidget * widget) {
    QRect rect = QApplication::desktop()->availableGeometry(widget);
    widget->move(rect.center() - widget->rect().center());
    }@

    the error i get is... mainwindow.cpp:16: error: invalid use of incomplete type 'struct QDesktopWidget'

    mainwindow.cpp
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "dialog.h"
    #include "ui_dialog.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    Dialog *q = new Dialog(this);
    q->show();
    }

    void centerWidgetOnScreen (QWidget * widget) {
    QRect rect = QApplication::desktop()->availableGeometry(widget);
    widget->move(rect.center() - widget->rect().center());
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }@

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kalster
      wrote on last edited by
      #2

      solved. I forget to include the desktop widget
      @#include <QDesktopWidget>@

      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