1 Ağustos 2018 Çarşamba

QWidget Sınıfı

activate metodu
Küçültülmüş pencereyi eski haline getirir. Şöyle yaparız.
QWidget * w = ...;
w->activate();
changeEvent metodu
Pencere küçültülürse veya büyütülürse çağrılır. Şöyle yaparız
void Form::changeEvent(QEvent * event)
{
  if(event->type() == QEvent::WindowStateChange)
  {
    if(isMinimized())
    {
      ...
    }
    else
    {
      ...
    }
  }
}
grabKeyboard metodu
Şöyle yaparız
QWidget * background = ...;
background->grabKeyboard();
installEventFilter metodu
Örnek
Şöyle yaparız.
w->installEventFilter(this);
Filtre için şöyle yaparız.
bool Myclass::eventFilter(QObject *obj, QEvent *event){
}
Örnek
Minize event'i yakalayıp iptal etmek için şöyle yaparız.
class EventFilter : public QObject
{
  Q_OBJECT
public:
  explicit EventFilter(QObject *parent = nullptr);
  bool eventFilter(QObject *watched, QEvent *event) override;
};

bool EventFilter::eventFilter(QObject *watched, QEvent *event)
{
  if (event->type() == QEvent::WindowStateChange) {
    auto e = static_cast<QWindowStateChangeEvent *>(event);
    auto window = static_cast<QWindow *>(watched);

    if (window->windowStates().testFlag(Qt::WindowMinimized)
      && ! e->oldState().testFlag(Qt::WindowMinimized))
    {
      // Restore old state
      window->setWindowStates(e->oldState());
      return true;
    }
  }

  // Do not filter event
  return false;
}
setAcceptDrops metodu
Şöyle yaparız.
QWidget* w = ...;
// this is to support drag and drop 
w->setAcceptDrops(true);
setWindowState metodu
Pencereyi küçültmek için şöyle yaparız.
QWidget * w = ...;
w->setWindowState(Qt::WindowMinimized);

QGuiApplication Sınıfı

exec metodu
Şöyle yaparız.
int main(int argc, char *argv[])
{
  QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

  QGuiApplication app(argc, argv);


  QQmlApplicationEngine engine;
  engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

  if (engine.rootObjects().isEmpty())
    return -1;

  auto root = engine.rootObjects().first();
  root->installEventFilter(new EventFilter());

  return app.exec();
}