I am trying to hide my QT application from taskbar? I cannot find anything in Google so I asking here.
Solution from Qt Hide Taskbar Item (Qt Hide Taskbar Item) and this->hide() is not helping.
main.cpp
#include "status_bar.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
status_bar w;
w.show();
return a.exec();
}
status_bar.cpp:
#include "status_bar.h"
#include "ui_status_bar.h"
#include <stdlib.h>
#include <QTime>
#include <QTimer>
#include <QApplication>
#include <QDesktopWidget>
status_bar::status_bar(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::status_bar)
{
ui->setupUi(this);
setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
resize(QApplication::desktop()->width(),36);
ui->time->move(QApplication::desktop()->width()-ui->time->size().width(),10);
ui->username->setText(getenv("USER"));
timeupdate = new QTimer(this);
connect(timeupdate, SIGNAL(timeout()),
this, SLOT(UpdateClock()));
timeupdate->start(100);
}
void status_bar::UpdateClock()
{
ui->time->setText(QTime::currentTime().toString("HH:mm"));
}
status_bar::~status_bar()
{
delete ui;
}
EDIT:
With code like this window is empty.
class MyWindowWidget : public QWidget
{
public:
MyWindowWidget(QWidget *parent)
: QWidget(parent, Qt::Dialog)
{
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
status_bar window;
MyWindowWidget widget(&window);
widget.show();
return app.exec();
}
Solved by using Qt::Tool flag.
Qt::Tool flag has other problems for me, like this widget/windows is hidden when its state becomes inactive.
I would recommend you to use Qt::ToolTip
Related
I am making a little app in Qt Creator, and I keep getting this error/warning from qt.pointer.dispatch:
qt.pointer.dispatch: delivering touch release to same window QWindow(0x0) not QWidgetWindow(0x14ef0d570, name="MainWindowWindow")
qt.pointer.dispatch: skipping QEventPoint(id=1 ts=0 pos=0,0 scn=1063.83,670.067 gbl=1063.83,670.067 Released ellipse=(1x1 ∡ 0) vel=0,0 press=-1063.83,-670.067 last=-1063.83,-670.067 Δ 1063.83,670.067) : no target window
I'm not doing anything special with touch release (as you can see below), and the error also doesn't affect the running of the program so far as I can tell. What is the problem and how do I fix it?
main.cpp
#include "mainwindow.hpp"
#include <QApplication>
#include <QLocale>
#include <QTranslator>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
for (const QString &locale : uiLanguages) {
const QString baseName = "Simulization_" + QLocale(locale).name();
if (translator.load(":/i18n/" + baseName)) {
a.installTranslator(&translator);
break;
}
}
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp
#include "mainwindow.hpp"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
I'm trying to ask for a password the user in order to access a particular section, my application is fullscreen. The problem is that when the qInputDialog appears also the unity taskbar and the application titlebar appears. I want to avoid this and keep my application fullscreen.
I'm using Qt 5.12.3 on Ubuntu 16.04
Take a look at this simple example:
Main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.showFullScreen();
return a.exec();
}
MainWindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QInputDialog>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
bool ok;
QString text = QInputDialog::getText(this, tr("Restriscted"),
tr("Password:"), QLineEdit::Password,"",&ok, Qt::FramelessWindowHint);
if (ok && text=="pass")
{
ui->label->setText("ok");
}
}
Seems there is no solution for this at the moment and the issue depends on Unity. At the end I replaced the qInputDialog with a qStackedView page with a qLabel and a qButton on it, then I hide/show the page accordingly.
I'd like to show and then close a dialog after 5 seconds. The dialog needs to be automatically resized (horizontally and vertically) based on the content of a label. Here is my code:
#include <QApplication>
#include <QDialog>
#include <QLabel>
#include <QTimer>
void notify (int intTime=1000)
{
QDialog notify;
notify.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
notify.setWindowFlag(Qt::FramelessWindowHint);
QLabel *lbl = new QLabel(¬ify);
lbl->setText("This is a test This is a test This is a test This is a test This is a test This is a test This is a test");
QApplication::processEvents();
notify.adjustSize();
QTimer::singleShot(intTime, ¬ify, SLOT(close()));
notify.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
notify(5000);
exit(0);
// return a.exec();
}
It does not not expand the dialog based on the label size. Here is how it looks:
How can I fix it? (Please also let me know if there is better way of doing this.)
I am using Qt5 in Linux.
Since you have not used a QLayout the QLabel will be displayed as large as you can, a possible request is to change the size of QDialog to the recommended size of QLabel with sizeHint():
#include <QApplication>
#include <QDialog>
#include <QLabel>
#include <QTimer>
void notify (int intTime=1000)
{
QDialog notify;
notify.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
notify.setWindowFlag(Qt::FramelessWindowHint);
QLabel *lbl = new QLabel(¬ify);
lbl->setText("This is a test This is a test This is a test This is a test This is a test This is a test This is a test");
QApplication::processEvents();
notify.resize(lbl->sizeHint());
QTimer::singleShot(intTime, ¬ify, SLOT(close()));
notify.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
notify(5000);
exit(0);
// return a.exec();
}
The other possible solution is to use a QLayout:
#include <QApplication>
#include <QDialog>
#include <QLabel>
#include <QTimer>
#include <QVBoxLayout>
void notify (int intTime=1000)
{
QDialog notify;
QVBoxLayout *lay = new QVBoxLayout(¬ify);
//notify.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
notify.setWindowFlag(Qt::FramelessWindowHint);
QLabel *lbl = new QLabel;
lay->addWidget(lbl);
lbl->setText("This is a test This is a test This is a test This is a test This is a test This is a test This is a test");
QApplication::processEvents();
QTimer::singleShot(intTime, ¬ify, SLOT(close()));
notify.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
notify(5000);
exit(0);
// return a.exec();
}
I am trying to open up my app with a child window first. I got some code that almost works, but I cannot for the life of me figure out what is wrong with it that won't let it delete old dialog windows, and when I click back into the child dialog I opened with, it glitches out and I just end back up at square one! What should I do to stop this problem?
main.cpp file
#include "mainwindow.h"
#include <QApplication>
#include "yes.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget MainWindow;
MainWindow.show();
yes popup(&MainWindow);
popup.show();
return a.exec();
}
.cpp file
#include "yes.h"
#include "ui_yes.h"
#include "mainwindow.h"
yes::yes(QWidget *parent) :
QDialog(parent),
ui(new Ui::yes)
{
ui->setupUi(this);
ui->label->setVisible(false);
}
yes::~yes()
{
delete ui;
}
void yes::on_pushButton_clicked()
{
auto no = new MainWindow();
no->show();
no->setAttribute(Qt::WA_DeleteOnClose);
no->show();
}
I want to use layout in qt5, but In Visual Studio 2015 the layout does not work?
Here is my code:
layout.h code
#ifndef LAYOUT_H
#define LAYOUT_H
#include <QtWidgets/QMainWindow>
#include "ui_layout.h"
class layout : public QMainWindow
{
Q_OBJECT
public:
layout(QWidget *parent = 0);
~layout();
private:
Ui::layoutClass ui;
};
#endif // LAYOUT_H
main.cpp
#include "layout.h"
#include <QtWidgets/QApplication>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QHBoxLayout>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
layout w;
QHBoxLayout hb;
QPushButton b("button 0");
QPushButton b1("button 1");
hb.addWidget(&b);
hb.addWidget(&b1);
w.setLayout(&hb);
w.show();
return a.exec();
}
Here is my result:
How to fix this problem?
QMainWindow is a special widget since it has default widgets like QStatusbar, QMenuBar, etc. When working with this widget we must place the new elements in the centralWidget.
So we must assign a widget that will be our centralWidget, and then to this we add the layouts as shown below:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
layout w;
w.setCentralWidget(new QWidget);
QHBoxLayout hb;
QPushButton b("button 0");
QPushButton b1("button 1");
hb.addWidget(&b);
hb.addWidget(&b1);
w.centralWidget()->setLayout(&hb);
w.show();
return a.exec();
}