How can I programmatically make a window fullscreen?
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new QNewScene(this);
ui->graphicsView->setScene(scene);
// here is some code that will make the window fullscreen
}
For example:
QTimer::singleShot(0, this, SLOT(showFullScreen()));
method to make your window full screen:
QWidget::showFullScreen()
check it here: https://doc.qt.io/qt-5/qwidget.html#showFullScreen
Related
I have three windows: MainWindow, SelectPreset, Preset.
The SelectPreset window is called from the MainWindow window.
And the Preset window is called from the SelectPreset window.
But I can't understand why the Preset window elements are blocked (At the same time, this happens for some reason in Debian, in other systems I did not notice this).
Here's how my files work:
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
.
.
.
SelectPreset select_preset;
select_preset.setModal(true);
select_preset.exec();
selectpreset.cpp
SelectPreset::SelectPreset(QWidget *parent) :
QDialog(parent),
ui_selectpreset(new Ui::SelectPreset)
{
ui_selectpreset->setupUi(this);
}
.
.
.
Preset preset;
preset.setModal(true);
preset.exec();
preset.cpp
Preset::Preset(QWidget *parent) :
QDialog(parent),
ui_preset(new Ui::Preset)
{
ui_preset->setupUi(this);
}
Preset preset(this);
preset.setModal(true);
preset.exec();
so I an new to C++ and QT and I am trying to add a widget to a scroll area but without a layout as I want the widgets to be click and dragged.
Here's my code (main window.cpp):
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "player_window.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
player_window *player = new player_window(ui->scrollArea_WidgetContents);
player->setGeometry(50,50,450,130);
ui->scrollArea_WidgetContents->layout()->addWidget(player);
}
Thanks!
I have a Qt application which simply captures from the default webcam and shows it on a QVideoWidget. In the ui, I have a simple MainWindow with a QGraphicsView inside a VerticalLayout:
ui design
My mainwindow.cpp=============================================
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_viewfinder = new QVideoWidget(ui->captureView);
m_camera = new QCamera(QCameraInfo::defaultCamera());
m_camera->setViewfinder(m_viewfinder);
m_camera->start();
}
MainWindow::~MainWindow()
{
m_camera->stop();
delete m_viewfinder;
delete m_camera;
delete ui;
}
When I execute this, I get the application running, but the video contents do not scale according to the mainwindow size. Examples:
When I start the application
Resizing mainwindow down
Resizing mainwindow up
Is there some way to make the video content resize well and fit the available area?
I have seen this answer: QVideoWidget: Video is cut off, but it doesn't offer any solution that works for me. When use the QGraphicsView-QGraphicsScene-QGraphicsVideoItem chain, I see nothing at all.
When you use the following instruction:
m_viewfinder = new QVideoWidget(ui->captureView);
You are setting as the parent of m_viewfinder to captureView, so the positions of m_viewfinder will be relative to captureView, but this does not indicate that it will be the same size as the parent.
One of the easiest ways to do this is to use a layout. Also, it is not necessary to create the QGraphicsWidget or the QVBoxLayout, so I recommend you to delete it and get the design as it was established by default:
and then we establish a layout that is placed in the centralWidget, and in this layout we add the QVideoWidget.
...
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_viewfinder = new QVideoWidget;
QVBoxLayout *lay = new QVBoxLayout(ui->centralWidget);
lay->addWidget(m_viewfinder);
m_camera = new QCamera(QCameraInfo::defaultCamera());
m_camera->setViewfinder(m_viewfinder);
m_camera->start();
}
...
In the following link you can find the complete example.
I have a QStackedWidget with a custom widget in it.
//mainwindow.h
private:
CentralWidget m_centralWidget;
//mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->stackedWidget->addWidget(&m_centralWidget);
}
Now i want to create a QSplitter, fill the Splitter with content and add this Splitter to the StackedWidget.
CentralWidget::CentralWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::CentralWidget)
{
ui->setupUi(this);
connect(ui->pbAddSplit, SIGNAL(pressed()), this, SLOT(addSplit()));
}
void CentralWidget::addSplit()
{
QWidget* parent = parentWidget();
QStackedWidget* stackedWidget = qobject_cast<QStackedWidget*>(parent);
if(!stackedWidget) {
return;
}
QSplitter* splitter = new QSplitter(Qt::Vertical);
splitter->addWidget(new QLabel("Banana"));
splitter->addWidget(this);
int nIndex = stackedWidget->addWidget(splitter);
stackedWidget->setCurrentIndex(nIndex);
}
The result should be a QLabel("Banana") as one Widget of the splitter and the CentralWidget as the other splitter-widget.
But i just get the QLabel("Banana") - SplitterHandle and the CentralWidget got lost somehow...
splitter->addWidget(this) is obviously wrong...
Replacing it with splitter->addWidget(new QLabel("Cherry")) will result in a correct SplitterWidget...
The problem seems to be the parenting, but i cant figure it out.
Any suggestions would be most welcome!
If I create my QDialog and show it modal with exec() everything works fine, but I need this no modal!
With show() the Dialog is empty!
ProgramLoading *programLoading = new ProgramLoading();
programLoading->show();
// some code
programLoading->done(0);
Constructor
ProgramLoading::ProgramLoading(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
setWindowFlags( Qt::CustomizeWindowHint ); // remove window border
}
Don't think something with Dialog code is wrong because it works with exec()!
Any hints? Thank you!
PS: I'm using QT plugin for VisualStudio 2008
mw (Default with Window Decoration):
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
sd = new SplashDialog();
sd->show();
QTimer::singleShot(10000,this,SLOT(closeSplashDialog()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::closeSplashDialog()
{
sd->close();
delete sd;
}
splash (UI having Label and Button):
SplashDialog::SplashDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SplashDialog)
{
ui->setupUi(this);
setWindowFlags( Qt::CustomizeWindowHint );
}
SplashDialog::~SplashDialog()
{
delete ui;
}
Splash Dialog opens and is being closed 10 seconds later as intended