QConnect find no such slot on QCombobox by Qt Creater - c++

I create a window which inherits from QWidget
I set a grid layout to that Window
I make a function called handleHeroChange(int index) in public slot inside that window
I add a Qcombobox to call the function handleHeroChange(int index).
Qtcreator keeps telling:
**QObject::connect: No such slot QWidget::handleHeroChange(int) in ../Testing/Window.cpp:92**
What did i do wrong?
THE CODE:
//Window.h
class Window : public QWidget
{
QGraphicsPixmapItem* avatar;
QGraphicsTextItem* heroNameItem;
QGraphicsTextItem* heroStrItem;
QGraphicsTextItem* heroDexItem;
QGraphicsTextItem* herointelItem;
public:
Window(QWidget *parent = 0);
public slots:
void handleHeroChange(int);
};
//Window.cpp
Window::Window(QWidget *parent)
: QWidget(parent)
{
QGridLayout *grid = new QGridLayout(this);
QComboBox *comboHeroClass = new QComboBox();
comboHeroClass->addItem("Witcher");
comboHeroClass->addItem("Maurander");
comboHeroClass->setCurrentIndex(1);
grid->addWidget(comboHeroClass, 2,3,1,1);
QComboBox::connect(comboHeroClass, SIGNAL(currentIndexChanged(int)),this, SLOT(handleHeroChange(int)));
}
void Window::handleHeroChange(int index){
QPixmap myImage;
if(index == 0){
}else if(index == 1){
}
}

class Window : public QWidget
{
Q_OBJECT
Add Q_OBJECT macro without semicolon to your class and rebuild your project.
Without this macro moc cannot find your class and doesn't create your slot(and some other things) That's why you get your error: you see your slot but it doesn't exist and you get runtime error

Related

Reveal password for dialog in Qt

I need to create a login dialog like this
image files: eyeOn.png, eyeOff.png
Requirements:
password is shown only when we CLICK AND HOLD the eyeOn icon (even when we click and hold and drag the mouse to area outside of the dialog, the password is still shown), when we release the mouse, password is covered again.
while password is shown, the eye icon is eyeOn. While password is covered, the eye icon is eyeOff.
I have just built the layout.
QGridLayout *mainlogin = new QGridLayout();
QLabel *usernameLabel = new QLabel;
usernameLabel->setWordWrap(true);
usernameLabel->setText("Username");
mainlogin->addWidget(usernameLabel, 0, 0);
QComboBox *usernameLineEdit = new QComboBox;
usernameLineEdit->setEditable(true);
usernameLabel->setBuddy(usernameLineEdit);
mainlogin->addWidget(usernameLineEdit, 0, 1);
QLabel *capslockShow = new QLabel;
capslockShow->setWordWrap(true);
capslockShow->setText(" ");
mainlogin->addWidget(capslockShow, 1, 1);
QLabel *passwordLabel = new QLabel;
passwordLabel->setWordWrap(true);
passwordLabel->setText("Password");
mainlogin->addWidget(passwordLabel, 2, 0);
QLineEdit *passwordLineEdit = new QLineEdit;
passwordLineEdit->setEchoMode(QLineEdit::Password);
QAction *myAction = passwordLineEdit->addAction(QIcon(":/eyeOff.png"), QLineEdit::TrailingPosition);
passwordLabel->setBuddy(passwordLineEdit);
mainlogin->addWidget(passwordLineEdit, 2, 1);
What should I do next? Pls help me with code snippet.
The solution is to add a QAction to the QLineEdit, this will create a QToolButton that we can obtain from the associatedWidgets() (it will be the second widget since the first one is the one associated with clearButton). Already having the QToolButton you must use the pressed and released signal.
passwordlineedit.h
#ifndef PASSWORDLINEEDIT_H
#define PASSWORDLINEEDIT_H
#include <QAction>
#include <QLineEdit>
#include <QToolButton>
class PasswordLineEdit: public QLineEdit
{
public:
PasswordLineEdit(QWidget *parent=nullptr);
private slots:
void onPressed();
void onReleased();
protected:
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void focusInEvent(QFocusEvent *event);
void focusOutEvent(QFocusEvent *event);
private:
QToolButton *button;
};
#endif // PASSWORDLINEEDIT_H
passwordlineedit.cpp
#include "passwordlineedit.h"
PasswordLineEdit::PasswordLineEdit(QWidget *parent):
QLineEdit(parent)
{
setEchoMode(QLineEdit::Password);
QAction *action = addAction(QIcon(":/eyeOff"), QLineEdit::TrailingPosition);
button = qobject_cast<QToolButton *>(action->associatedWidgets().last());
button->hide();
button->setCursor(QCursor(Qt::PointingHandCursor));
connect(button, &QToolButton::pressed, this, &PasswordLineEdit::onPressed);
connect(button, &QToolButton::released, this, &PasswordLineEdit::onReleased);
}
void PasswordLineEdit::onPressed(){
QToolButton *button = qobject_cast<QToolButton *>(sender());
button->setIcon(QIcon(":/eyeOn"));
setEchoMode(QLineEdit::Normal);
}
void PasswordLineEdit::onReleased(){
QToolButton *button = qobject_cast<QToolButton *>(sender());
button->setIcon(QIcon(":/eyeOff"));
setEchoMode(QLineEdit::Password);
}
void PasswordLineEdit::enterEvent(QEvent *event){
button->show();
QLineEdit::enterEvent(event);
}
void PasswordLineEdit::leaveEvent(QEvent *event){
button->hide();
QLineEdit::leaveEvent(event);
}
void PasswordLineEdit::focusInEvent(QFocusEvent *event){
button->show();
QLineEdit::focusInEvent(event);
}
void PasswordLineEdit::focusOutEvent(QFocusEvent *event){
button->hide();
QLineEdit::focusOutEvent(event);
}
The complete example can be downloaded from the following link.
Rather than trying to make use of the QAction returned by QLineEdit::addAction you could probably use a QWidgetAction for this when combined with a suitable event filter...
class eye_spy: public QWidgetAction {
using super = QWidgetAction;
public:
explicit eye_spy (QLineEdit *control, QWidget *parent = nullptr)
: super(parent)
, m_control(control)
, m_on(":/eyeOn")
, m_off(":/eyeOff")
, m_pixmap_size(50, 50)
{
m_label.setScaledContents(true);
m_control->setEchoMode(QLineEdit::Password);
m_label.setPixmap(m_off.pixmap(m_pixmap_size));
m_label.installEventFilter(this);
setDefaultWidget(&m_label);
}
protected:
virtual bool eventFilter (QObject *obj, QEvent *event) override
{
if (event->type() == QEvent::MouseButtonPress) {
m_control->setEchoMode(QLineEdit::Normal);
m_label.setPixmap(m_on.pixmap(m_pixmap_size));
} else if (event->type() == QEvent::MouseButtonRelease) {
m_control->setEchoMode(QLineEdit::Password);
m_label.setPixmap(m_off.pixmap(m_pixmap_size));
}
return(super::eventFilter(obj, event));
}
private:
QLineEdit *m_control;
QLabel m_label;
QIcon m_on;
QIcon m_off;
QSize m_pixmap_size;
};
Now, rather than...
QAction *myAction = passwordLineEdit->addAction(QIcon(":/eyeOff.png"), QLineEdit::TrailingPosition);
Use...
eye_spy eye_spy(passwordLineEdit);
passwordLineEdit->addAction(&eye_spy, QLineEdit::TrailingPosition);
Seems to provide the desired behaviour.

Qt: Context menu / connect with parameters

I have a problem connecting context menu actions in Qt. I know there are plenty of similar questions around, nevertheless I couldn't find a solution yet.
I have a series of plots built using QCustomplot.
What I want to do is to create a context menu when right-clicking on the background of each plot listing all the signal present in the graph. By clicking an entry of this menu, the corresponding signal should be hidden (if currently visible) or made visible (if hidden).
Now, I've defined a class called PlotHandler of which I paste the relevant parts here below:
plotHandler.cpp
#include "plothandler.h"
PlotHandler::PlotHandler(QStringList groupNames, int startIdx, QWidget *parent) :
QWidget(parent), scrolling(false), refreshing(true)
{
pPlot = new QCustomPlot(this);
pPlot->setContextMenuPolicy(Qt::CustomContextMenu);
connect(pPlot, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequest(QPoint)));
}
void PlotHandler::contextMenuRequest(QPoint pos)
{
int i;
QMenu *menu = new QMenu(this);
for(i=0; i<pGroup->getDataLength(); i++)
{
QAction *menuEntry;
menuEntry = new QAction(pPlot->graph(i)->name(), this);
menuEntry->setProperty("graphIdx", i);
menu->addAction(menuEntry);
connect(menuEntry, SIGNAL(triggered()), this, SLOT(addRemoveGraph()));
}
menu->popup(pPlot->mapToGlobal(pos));
}
void PlotHandler::addRemoveGraph()
{
QAction *selectedSignal = qobject_cast<QAction *>(sender());
int tmp = selectedSignal->property("graphIdx").toInt();
if (pPlot->graph(tmp)->visible())
{
pPlot->graph(tmp)->setVisible(false);
}
else
{
pPlot->graph(tmp)->setVisible(true);
}
}
plotHandler.h
class PlotHandler : public QWidget
{
Q_OBJECT
public:
explicit PlotHandler(QStringList groupNames, int startIdx, QWidget *parent = 0);
QString groupRequested();
private:
QCustomPlot *pPlot;
public slots:
void contextMenuRequest(QPoint pos);
void addRemoveGraph();
}
The menu is correctly showed with the right entries and when I click on an action addRemoveGraph is called. In debug it gives back the following message:
The inferior stopped because it triggered an exception. Stopped in
thread 0 by: Exception at 0x5d6c2f9a, code: 0xc0000005: read access
violation at: 0x0, flags=0x0.
trying to execute
int tmp = selectedSignal->property("graphIdx").toInt();
Could anyone point me towards the right direction?
Thanks in advance
You use QObject::setProperty but QAction doesn't have a property named "graphIdx". When you attempt to read the "graphIdx" property from QAction you will always get an invalid QVariant.
int tmp = selectedSignal->property("graphIdx").toInt();
// tmp always is 0;
You can use QAction::setData if you need to store only one property. Otherwise, use QObject::setProperty to set a custom property on any QObject. QAction is a QObject.
Here below the solution that solved the issue.
plotHandler.cpp
#include "plothandler.h"
PlotHandler::PlotHandler(QStringList groupNames, int startIdx, QWidget *parent) :
QWidget(parent), scrolling(false), refreshing(true)
{
pPlot = new QCustomPlot(this);
pPlot->setContextMenuPolicy(Qt::CustomContextMenu);
connect(pPlot, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequest(QPoint)));
}
void PlotHandler::contextMenuRequest(QPoint pos)
{
int i;
QMenu *menu = new QMenu(this);
for(i=0; i<pGroup->getDataLength(); i++)
{
QAction *menuEntry;
menuEntry = new QAction(pPlot->graph(i)->name(), this);
menuEntry->setData(i);
menu->addAction(menuEntry);
}
connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(addRemoveGraph(QAction*)));
menu->popup(pPlot->mapToGlobal(pos));
}
void PlotHandler::addRemoveGraph(QAction *selectedSignal)
{
int tmp = selectedSignal->property("graphIdx").toInt();
if (pPlot->graph(tmp)->visible())
{
pPlot->graph(tmp)->setVisible(false);
}
else
{
pPlot->graph(tmp)->setVisible(true);
}
pPlot->replot();
}
plotHandler.h
class PlotHandler : public QWidget
{
Q_OBJECT
public:
explicit PlotHandler(QStringList groupNames, int startIdx, QWidget *parent = 0);
QString groupRequested();
private:
QCustomPlot *pPlot;
public slots:
void contextMenuRequest(QPoint pos);
void addRemoveGraph();
}
Thanks everyone for your help.

Qt method call from another class?

I got two windows(two classes), one window that opens another when i click a button.
then the user inputs something into the newly opened window and then transfer that information to the first window when a button is clicked
The problem is I can't seem to send something to the second window so i can send the user input back to the main window. I read a few places that I should use Q_object but not really sure how that works
I should mention that I am new to Qt and didn't know about the designer there is in qt creator before i was way to ahead with the program.
Hope you have some ideas to how I can do this
edit1:
I should show the relevant code i have
Mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
//alot of stuff not relevant right now creating different stuff
changeProfile= new QPushButton("ændre valgte profil",this);
profileList = new QComboBox(this);
cProfile = new CreateProfile;
connect(changeProfile,SIGNAL(clicked()),this,SLOT(ProfileChange()));
}
void MainWindow::ProfileChange()
{
file pfile(profileList->currentText().toStdString());
string tempName = pfile.read(light);
cProfile->setValue(light,tempName);
cPr
ofile->show();
}
void MainWindow::setProfileList(QString Pname_)
{
bool found = 0;
for (int i = 0;i<5;i++)
{
if (Pname_ ==profileList->itemText(i))
found = 1;
}
if (found !=1)
profileList->addItem(Pname_);
}
createProfile.cpp
CreateProfile::CreateProfile(QWidget *parent)
:QMainWindow(parent)
{
//alot of other irrelevant stuff here
saveP = new QPushButton("Save",this);
connect(saveP,SIGNAL(clicked()),this,SLOT(saveProfile()));
}
void CreateProfile::saveProfile()
{
temp = pName->text();
file pFile(temp.toStdString());
bool lights[2] = {light1->checkState(),light2->checkState()};
if (temp.length() == 0)
{
MessageBox(NULL,"Du har ikke skrevet noget navn ind\n Prov igen","Error",MB_ICONWARNING+MB_SETFOREGROUND);
}
else
{
pFile.save(lights);
//call function setProfileList
this->hide();
}
}
If that makes sence, If you need the .h file too i can show them also
I need to call setProfileList from the mainwindow in the function saveprofile(there is in createprofile window) or if there is a way i can change the combobox in the wainwindow from the createprofile window?
edit 2:
mainwindow.h
#include "createprofile.h"
class MainWindow : public QMainWindow
{
Q_OBJECT
public slots:
void ProfileChange();
//some other button clicks
public:
CreateProfile *cProfile;
void setProfileList(QString Pname_);
//other irelevant stuff
private:
// and some private members
};
createProfile.h
class CreateProfile : public QMainWindow
{
Q_OBJECT
public slots:
void saveProfile();
public:
explicit CreateProfile(QWidget *parent = 0);
~CreateProfile();
//and other stuff there isnt relevant
};
You are looking for the Qt signal-slot mechanism, namely:
class SecondWindow : public QMainWindow
{
Q_OBJECT
public:
SecondWindow(QWidget *parent = Q_NULLPTR) : QObject(Q_NULLPTR)
{
// ...
connect(secondWindowButton, SIGNAL(clicked(bool)), SLOT(handleClicked()));
// ...
}
public slots:
void SecondWindow::handleClicked()
{
// Gather information from the UI as you wish
firstWindow->foo();
}
// ...
}
or, if you have a container class for the windows, you could handle it in there, too, as follows:
connect(secondWindow->myButton, SIGNAL(clicked(bool)), SLOT(handleClicked()));
I found a very different way to do this, so I have made a QComboBox in the constructor of createProfile.cpp and then I have access to the profileList this way.

Cannot display a tree (QTreeView) inside a QWidget placed inside another QWidget

I have a problem with a QWidget that contains a tree (QTreeView): I can display it if it is created as a widget on its own, and I cannot do the same if it is a subwidget of another higher level widget. In this second case, what I get is an empty widget without the tree.
This works:
QApplication testApp(argc, argv);
MyTree myTree;
testApp.exec();
This does not work:
class MainWindow : public QMainWindow
{
Q_OBJECT
QSplitter *spl1, *spl2;
QMdiArea *mdiArea;
QTableWidget *other;
public:
MainWindow();
void LoadTree();
MyTree *myTree;
};
MainWindow::MainWindow(QWidget *_parent)
: QMainWindow(_parent), myTree(0)
{
mdiArea = new QMdiArea;
other = new QTableWidget;
spl1 = new QSplitter(Qt::Vertical, this);
spl1->addWidget(mdiArea);
spl1->addWidget(other);
LoadTree();
spl2 = new QSplitter(Qt::Horizontal, this);
spl2->addWidget(myTree);
spl2->addWidget(spl1);
setCentralWidget(spl2);
}
void MainWindow::LoadTree()
{
myTree = new MyTree(this);
}
Here is the code common to the two cases (which should be OK):
class MyTree : public QWidget
{
Q_OBJECT
public:
explicit MyTree(QWidget *_parent = 0);
int RefreshTree();
private slots:
void HandleTreeWidgetEvent(QModelIndex);
private:
QWidget *parent;
QTreeView *pjrTree;
QTreeView *GetNewTree();
};
MyTree::MyTree(QWidget *_parent) :
QWidget(_parent),
parent(_parent)
{
pjrTree = GetNewTree();
if(pjrTree) {
if(parent == 0)
pjrTree->show();
}
else {
// Never gets here
}
}
QTreeView* MyTree::GetNewTree()
{
QFileSystemModel *model = new QFileSystemModel;
model->setReadOnly(true);
model->setRootPath("/my/path/");
QTreeView* pjrTree = new QTreeView;
pjrTree->setModel(model);
pjrTree->setRootIndex(model->index("/my/path/"));
QModelIndex index;
index = model->index(4, 1); // temp values - no effect
return pjrTree;
}
Is the tree view the only widget that does not display? I would suggest passing the splitter it will be contained in as the parent, rather than the main window, when you instantiate the tree.
Deriving the class MyTree from QTreeView, instead of having a pointer to QTreeView as a member variable, fixed my problem.

Making a borderless window with for Qt

I'm new to Qt C++. I downloaded the latest windows version, did some tutorials and its great.
I saw some styling options that the Qt framework has and its great, but now I need to build my application that its main windows (form) it designed/skinned with image without the rectangle borders (borderless?).
How can I do it with Qt?
If your looking for some advanced styling in the shape of a widget, maybe this example will help you:
Shaped Clock Example
Or maybe you're simply looking for this kind of flag: Qt::CustomizeWindowHint or simply Qt::FramelessWindowHint.
I created a small example, of how to create VS2013 like frameless window in Qt5:
You can get the complete sources here: https://github.com/Jorgen-VikingGod/Qt-Frameless-Window-DarkStyle
Otherwise here a code overview of how to embed the "main" mainwindow into the "frameless" window. Also you can see how to add titlebar, buttons and do maximize, resize and move of the frameless window.
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtWidgets>
/*
place your QMainWindow code here
*/
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
/*
this class is to add frameless window supoort and do all the stuff with titlebar and buttons
*/
class BorderlessMainWindow: public QMainWindow
{
Q_OBJECT
public:
explicit BorderlessMainWindow(QWidget *parent = 0);
~BorderlessMainWindow() {}
protected:
void mouseMoveEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void mouseDoubleClickEvent(QMouseEvent *event);
private slots:
void slot_minimized();
void slot_restored();
void slot_maximized();
void slot_closed();
private:
MainWindow *mMainWindow;
QWidget *mTitlebarWidget;
QLabel *mWindowTitle;
QPushButton *mMinimizeButton;
QPushButton *mRestoreButton;
QPushButton *mMaximizeButton;
QPushButton *mCloseButton;
QPoint mLastMousePosition;
bool mMoving;
bool mMaximized;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
/*
frameless window class: it adds the MainWindow class inside the centralWidget
*/
BorderlessMainWindow::BorderlessMainWindow(QWidget *parent) : QMainWindow(parent, Qt::CustomizeWindowHint ) {
setObjectName("borderlessMainWindow");
setWindowFlags(Qt::FramelessWindowHint| Qt::WindowSystemMenuHint);
// to fix taskbar minimize feature
setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint);
mMainWindow = new MainWindow(this);
setWindowTitle(mMainWindow->windowTitle());
QVBoxLayout *verticalLayout = new QVBoxLayout();
verticalLayout->setSpacing(0);
verticalLayout->setMargin(1);
QHBoxLayout *horizontalLayout = new QHBoxLayout();
horizontalLayout->setSpacing(0);
horizontalLayout->setMargin(0);
mTitlebarWidget = new QWidget(this);
mTitlebarWidget->setObjectName("titlebarWidget");
mTitlebarWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
mTitlebarWidget->setLayout(horizontalLayout);
mMinimizeButton = new QPushButton(mTitlebarWidget);
mMinimizeButton->setObjectName("minimizeButton");
connect(mMinimizeButton, SIGNAL(clicked()), this, SLOT(slot_minimized()));
mRestoreButton = new QPushButton(mTitlebarWidget);
mRestoreButton->setObjectName("restoreButton");
mRestoreButton->setVisible(false);
connect(mRestoreButton, SIGNAL(clicked()), this, SLOT(slot_restored()));
mMaximizeButton = new QPushButton(mTitlebarWidget);
mMaximizeButton->setObjectName("maximizeButton");
connect(mMaximizeButton, SIGNAL(clicked()), this, SLOT(slot_maximized()));
mCloseButton = new QPushButton(mTitlebarWidget);
mCloseButton->setObjectName("closeButton");
connect(mCloseButton, SIGNAL(clicked()), this, SLOT(slot_closed()));
mWindowTitle = new QLabel(mTitlebarWidget);
mWindowTitle->setObjectName("windowTitle");
mWindowTitle->setText(windowTitle());
horizontalLayout->addWidget(mWindowTitle);
horizontalLayout->addStretch(1);
horizontalLayout->addWidget(mMinimizeButton);
horizontalLayout->addWidget(mRestoreButton);
horizontalLayout->addWidget(mMaximizeButton);
horizontalLayout->addWidget(mCloseButton);
verticalLayout->addWidget(mTitlebarWidget);
verticalLayout->addWidget(mMainWindow);
QWidget *centralWidget = new QWidget(this);
centralWidget->setObjectName("centralWidget");
centralWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
centralWidget->setLayout(verticalLayout);
setCentralWidget(centralWidget);
}
void BorderlessMainWindow::mousePressEvent(QMouseEvent* event) {
if (!mTitlebarWidget->underMouse() && !mWindowTitle->underMouse())
return;
if(event->button() == Qt::LeftButton) {
mMoving = true;
mLastMousePosition = event->pos();
}
}
void BorderlessMainWindow::mouseMoveEvent(QMouseEvent* event) {
if (!mTitlebarWidget->underMouse() && !mWindowTitle->underMouse())
return;
if( event->buttons().testFlag(Qt::LeftButton) && mMoving) {
this->move(this->pos() + (event->pos() - mLastMousePosition));
}
}
void BorderlessMainWindow::mouseReleaseEvent(QMouseEvent* event) {
if (!mTitlebarWidget->underMouse() && !mWindowTitle->underMouse())
return;
if(event->button() == Qt::LeftButton) {
mMoving = false;
}
}
void BorderlessMainWindow::mouseDoubleClickEvent(QMouseEvent *event) {
Q_UNUSED(event);
if (!mTitlebarWidget->underMouse() && !mWindowTitle->underMouse())
return;
mMaximized = !mMaximized;
if (mMaximized) {
slot_maximized();
} else {
slot_restored();
}
}
void BorderlessMainWindow::slot_minimized() {
setWindowState(Qt::WindowMinimized);
}
void BorderlessMainWindow::slot_restored() {
mRestoreButton->setVisible(false);
mMaximizeButton->setVisible(true);
setWindowState(Qt::WindowNoState);
setStyleSheet("#borderlessMainWindow{border:1px solid palette(highlight);}");
}
void BorderlessMainWindow::slot_maximized() {
mRestoreButton->setVisible(true);
mMaximizeButton->setVisible(false);
setWindowState(Qt::WindowMaximized);
setStyleSheet("#borderlessMainWindow{border:1px solid palette(base);}");
}
void BorderlessMainWindow::slot_closed() {
close();
}
/*
MainWindow class: put all your code here
*/
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent, Qt::FramelessWindowHint), ui(new Ui::MainWindow) {
ui->setupUi(this);
statusBar()->setSizeGripEnabled(true);
}
MainWindow::~MainWindow() {
delete ui;
}
There is a sample application in your Qt directory: examples/widgets/windowsflags.
I ran into this myself and figured it out after some time. Check out https://github.com/ianbannerman/TrueFramelessWindow for sample code for both Windows & macOS.
Qt::FramelessWindowHint sacrifices resizing and min/max/close, so is probably not what mot people are looking for.