[英]Detect Screen Rotation in Qt issues
我想對屏幕旋轉進行一些更改,應該處理此類事件的方法的代碼取自這里
編輯:我有一個滾動區域,它在旋轉時獲得邊框我如何調整它的大小?所以它可以適合屏幕請檢查下面的事件處理程序我的整個代碼:
//FORM1.CPP
#include "form1.h"
#include "ui_form1.h"
#include "form.h"
#include "ui_form.h"
#include <QResizeEvent>
Form1::Form1(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form1)
{
ui->setupUi(this);
}
Form1::~Form1()
{
delete ui;
}
//the method that is supposed to handle such event
void Form1::resizeEvent (QResizeEvent* event)
{
QWidget::resizeEvent(event);
ui->textBrowser->setText("karim");
}
我收到了這個錯誤:
\Users\user\Desktop\karim\Qt\Project\form1.cpp:31: error: 'QMyWidget' has not been declared
請注意,我沒有做任何其他事情,這是我的全部代碼......你能告訴我有什么問題或沒有得到什么嗎?
請具體說明我將不勝感激...
您必須創建插槽
connect(qApp->desktop(), SIGNAL(resized(int)), this, SLOT(onResized(int)));
並像這樣實現它:
void Widget::onResized(int)
{
QDesktopWidget* screen = qApp->desktop();
QSize displaySize;
if (screen) {
displaySize = screen->screenGeometry().size();
if (displaySize != this->size()) {
this->resize(displaySize);
}
}
}
除了以下行之外,我沒有看到對您的QMyWidget
class 的任何引用。 可能是我錯過了一些東西。 但是,如果您在其他地方定義了QMyWidget
class,您至少需要包含 header。
void QMyWidget::resizeEvent(QResizeEvent* event)
{
ui->labelk->setText("blabla");
}
可能你的意思是這個而不是上面的:
void Form1::resizeEvent(QResizeEvent* event)
{
ui->labelk->setText("blabla");
}
更新評論:您可以嘗試這樣做。
void Form1::resizeEvent(QResizeEvent* event)
{
// call the base class for the default behavior
QWidget::resizeEvent(event);
// Add your custom changes here
ui->labelk->setText("blabla");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.