QTableWidget with QPushbutton inside: resize problem - qt

I'm an absolute beginner of Qt. I have the following MWE.
#include <QApplication>
#include <QTableWidget>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableWidget table;
table.setRowCount(2);
table.setColumnCount(3);
QPushButton button("Push me");
table.setCellWidget(1, 1, &button);
table.show();
return a.exec();
}
I notice that when I resize the column of the table holding the mousebutton down the PushButton remain of the same dimension and it adjust to the correct size only when the mousebutton is released. Is this a wanted feature? How can I avoid it?
EDIT
My setups are
Qt 5.15.0 on Linux
Qt 5.15.0 via PySide2 on Linux
Qt 5.15.0 on Windows

Related

QML application virtual keyboard behind fullscreen application

I want to use Qt virtual keyboard in my QML application. I use Qt 5.9.4 and I am on Windows 7.
I tried the Qt example called "basic", it works in "windowed" mode, but when I put the application window in full screen with
view.showFullScreen(); // instead of view.show() for windowed mode
the keyboard appears behind the application window and not above it, so it's not usable.
How to correct that?
EDIT:
Sorry, as I talk about Qt example, I thought, wrongly, that everyone had it.
Here is the code:
#include <QQuickView>
#include <QGuiApplication>
#include <QQmlEngine>
int main(int argc, char *argv[])
{
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
QGuiApplication app(argc, argv);
QQuickView view(QString("qrc:/%2").arg(MAIN_QML));
if (view.status() == QQuickView::Error)
return -1;
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.showFullScreen();
return app.exec();
}

Getting the value of a QLabel with an accessible name using UI Automation

I'm trying to write an UI test (using Windows UI Automation) for an application that uses a QLabel to show an output to a user.
I create the label like this:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow w;
w.setWindowTitle("MyWindowTitle");
auto centralWidget = new QWidget(&w);
centralWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
QVBoxLayout layout(centralWidget);
auto interrestingLabel = new QLabel(centralWidget);
QString valueCalculatedByApp = "1337";
interrestingLabel->setText(valueCalculatedByApp);
//interrestingLabel->setAccessibleName("MyAccessibleName");
layout.addWidget(interrestingLabel);
auto uninterrestingLabel = new QLabel(centralWidget);
uninterrestingLabel->setText("uninterrestingText");
layout.addWidget(uninterrestingLabel);
w.setCentralWidget(centralWidget);
w.show();
return a.exec();
}
Inspect.exe now shows the value "1337" as name of the widget:
Without accessible name
The problem with this would be that my UI test would need to figure out which one is the correct label.
If I uncomment setAccessibleName line, the widget is now identifiable, but I the text is no longer in visible in the properties.
With accessible name
Is there a way to read the text of a QLabel with an accessible name, or is there another way to make the QLabel identifieable while still being able to read the text?
I found a workaround:
Instead of a QLabel I use a QLineEdit. I set enabled to false so it is not selectable or editable (Like a QLabel) and use QSS to make it look like a QLabel:
#include <QApplication>
#include <QLabel>
#include <QLineEdit>
#include <QMainWindow>
#include <QSizePolicy>
#include <QVBoxLayout>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setAttribute(Qt::AA_NativeWindows);
QMainWindow w;
w.setWindowTitle("MyWindowTitle");
auto centralWidget = new QWidget(&w);
centralWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
QVBoxLayout layout(centralWidget);
auto interrestingLabel = new QLineEdit(centralWidget);
QString valueCalculatedByApp = "1337";
interrestingLabel->setText(valueCalculatedByApp);
interrestingLabel->setAccessibleName("MyAccessibleName");
interrestingLabel->setEnabled(false);
interrestingLabel->setStyleSheet(
"border-style: none;"
"color: black;"
"background:transparent"
);
layout.addWidget(interrestingLabel);
auto uninterrestingLabel = new QLabel(centralWidget);
uninterrestingLabel->setText("uninterrestingText");
layout.addWidget(uninterrestingLabel);
w.setCentralWidget(centralWidget);
w.show();
return a.exec();
}

Having trouble drawing an image in Qt using QGraphicsScene

The code below loads an image using QLabel. The code uses: myLabel.setMask(pixmap.mask()); and it works as it should. The problem comes when I try and load an image using QGraphicsScene.
#include <QApplication>
#include <QLabel>
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel myLabel;
QPixmap pixmap("/path/tomy/image.jpg");
myLabel.setPixmap(pixmap);
myLabel.setMask(pixmap.mask());
myLabel.show();
return app.exec();
}
In this code I am attempting to the same as above but using QGraphicsScene. The pixmap is loaded properly, after that I am not sure why the program is not working properly. Is it because there is no setMask() operation? Or is there an operation missing that is needed to make the image visible?
#include <QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#else
#include <QtGui>
#endif
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPixmap pixmap("/path/tomy/image.jpg");
QGraphicsPixmapItem item( pixmap);
QGraphicsScene* scene = new QGraphicsScene;
scene->addItem(&item);
QGraphicsView view(scene);
view.show();
return a.exec();
}

How to play video by internet link with QT using QMediaPlayer object

I want to play video using QMediaplayer with internet link. I tried to do this by passing internet link to "setMedia" function but error occured:
"DirectShowPlayerService::doRender: Unresolved error code 80040218"
Example Code is:
#include "mainwindow.h"
#include <QApplication>
#include <QMediaPlayer>
#include <QVideoWidget>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//MainWindow w;
//w.show();
QMediaPlayer * player = new QMediaPlayer;
QVideoWidget * vw = new QVideoWidget;
player->setVideoOutput(vw);
player->setMedia(QUrl("http://21.179.127.116/Katy%20Perry%20-%20Roar%20(Official).mp4"));
vw->setGeometry(100,100,300,400);
vw->show();
player->play();
qDebug()<<player->state();
return a.exec();
}
I am using Qt Creator 3.5.1 (enterprise)

Error Occured while designing Dialog in Qt

The program name is GoToCell in the form I created a label and two push buttons and I wrote the code in main.cpp as follows:
#include <QtGui/QApplication>
#include<QDialog>
#include "ui_GoToCell.h"
#include "GoToCell.h"
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
Ui::GoToCell ui;
QDialog *dialog=new QDialog;
ui.setupUi(dialog);
dialog->show();
return a.exec();
}
While running it I'm getting the following errors:
GoToCell is not a member of ui
What should I do?
I think you have misspelled object name in objectName property in the GoToCell.ui form.
Change it to GoToCell. It will then execute.

Resources