To what I've done: I converted a XML file from Qt Designer via the uic tool to a header file and tried to open and run that in VS2019 and VS2017.
The problem:
VS2019/2017 gives me errors (E0020, E1696, maybe so others too) and I think VS can't import the Qt libraries, even though I installed
"Qt Visual Studio Tools" and I don't know how to fix that now.
The errors look something like this:
E1696: the file "source" can't be opened: "QtWidgets/QFrame" (and other QtWidget, QtCore, and QtGui libraries)
E0020: the identifier "QtPushButton" is not defined (and other widgets like "QtLabel", "QtScrollbar", etc)
The second question would be: When the first one is fixed, how do I run the code, that creates the window from that header file? In Qt Designer I only had to press the "run" button and it ran the main function. Does it work the same way with the created header file and the main from Qt Designer?
header file (created via uic):
/*******************************************************************************
** Created by: Qt User Interface Compiler version 5.13.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef PATCHBOT_GUI_H
#define PATCHBOT_GUI_H
#include <QtCore/QVariant>
#include <QtGui/QIcon>
#include <QtWidgets/QApplication>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QFrame>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QScrollBar>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *centralwidget;
QGridLayout *gridLayout;
QFrame *selectColonyFrame;
QPushButton *selectColonyButton;
QFrame *currentColonyFrame;
QLabel *currentColonyLabel;
QFrame *missionControlsFrame;
QVBoxLayout *verticalLayout;
QLabel *misisonControlsLabel;
QGridLayout *missionControlsGridLayout;
QPushButton *startButton;
QPushButton *abortButton;
QPushButton *singleStepButton;
QPushButton *autoButton;
QPushButton *pauseButton;
QFrame *botControlsFrame;
QGridLayout *gridLayout_2;
QGridLayout *botControlsGridLayout;
QPushButton *downButton;
QPushButton *upButton;
QPushButton *waitButton;
QPushButton *leftButton;
QPushButton *deleteButton;
QPushButton *rightButton;
QLabel *botControlsLabel;
QComboBox *repeatDropdown;
QFrame *frame_6;
QFrame *botCommandFrame;
QTextEdit *botCommandTextEdit;
QFrame *mapFrame;
QGridLayout *gridLayout_6;
QLabel *label;
QScrollBar *verticalScrollBar;
QScrollBar *horizontalScrollBar;
QMenuBar *menubar;
QStatusBar *statusbar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(819, 634);
MainWindow->setMinimumSize(QSize(580, 400));
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
gridLayout = new QGridLayout(centralwidget);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
gridLayout->setVerticalSpacing(6);
gridLayout->setContentsMargins(-1, 0, -1, 0);
selectColonyFrame = new QFrame(centralwidget);
selectColonyFrame->setObjectName(QString::fromUtf8("selectColonyFrame"));
selectColonyFrame->setMinimumSize(QSize(150, 40));
selectColonyFrame->setLayoutDirection(Qt::RightToLeft);
selectColonyFrame->setFrameShape(QFrame::StyledPanel);
selectColonyFrame->setFrameShadow(QFrame::Raised);
selectColonyButton = new QPushButton(selectColonyFrame);
selectColonyButton->setObjectName(QString::fromUtf8("selectColonyButton"));
selectColonyButton->setGeometry(QRect(80, 0, 150, 40));
selectColonyButton->setMinimumSize(QSize(150, 40));
selectColonyButton->setMaximumSize(QSize(150, 50));
QFont font;
font.setPointSize(11);
font.setBold(true);
font.setWeight(75);
selectColonyButton->setFont(font);
gridLayout->addWidget(selectColonyFrame, 0, 1, 1, 1);
currentColonyFrame = new QFrame(centralwidget);
currentColonyFrame->setObjectName(QString::fromUtf8("currentColonyFrame"));
QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(currentColonyFrame->sizePolicy().hasHeightForWidth());
currentColonyFrame->setSizePolicy(sizePolicy);
currentColonyFrame->setMinimumSize(QSize(0, 25));
currentColonyFrame->setFrameShape(QFrame::StyledPanel);
currentColonyFrame->setFrameShadow(QFrame::Raised);
currentColonyLabel = new QLabel(currentColonyFrame);
currentColonyLabel->setObjectName(QString::fromUtf8("currentColonyLabel"));
currentColonyLabel->setGeometry(QRect(10, 10, 301, 16));
currentColonyLabel->setMinimumSize(QSize(220, 15));
currentColonyLabel->setMaximumSize(QSize(460, 25));
QFont font1;
font1.setPointSize(10);
currentColonyLabel->setFont(font1);
gridLayout->addWidget(currentColonyFrame, 0, 0, 1, 1);
missionControlsFrame = new QFrame(centralwidget);
missionControlsFrame->setObjectName(QString::fromUtf8("missionControlsFrame"));
QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy1.setHorizontalStretch(8);
sizePolicy1.setVerticalStretch(8);
sizePolicy1.setHeightForWidth(missionControlsFrame->sizePolicy().hasHeightForWidth());
missionControlsFrame->setSizePolicy(sizePolicy1);
missionControlsFrame->setMaximumSize(QSize(300, 180));
missionControlsFrame->setFrameShape(QFrame::WinPanel);
missionControlsFrame->setFrameShadow(QFrame::Raised);
verticalLayout = new QVBoxLayout(missionControlsFrame);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
misisonControlsLabel = new QLabel(missionControlsFrame);
misisonControlsLabel->setObjectName(QString::fromUtf8("misisonControlsLabel"));
QFont font2;
font2.setPointSize(11);
misisonControlsLabel->setFont(font2);
misisonControlsLabel->setAlignment(Qt::AlignCenter);
verticalLayout->addWidget(misisonControlsLabel);
missionControlsGridLayout = new QGridLayout();
missionControlsGridLayout->setObjectName(QString::fromUtf8("missionControlsGridLayout"));
missionControlsGridLayout->setHorizontalSpacing(20);
missionControlsGridLayout->setVerticalSpacing(10);
missionControlsGridLayout->setContentsMargins(15, 20, 15, 0);
startButton = new QPushButton(missionControlsFrame);
startButton->setObjectName(QString::fromUtf8("startButton"));
startButton->setMinimumSize(QSize(80, 30));
startButton->setMaximumSize(QSize(130, 50));
QFont font3;
font3.setPointSize(12);
startButton->setFont(font3);
missionControlsGridLayout->addWidget(startButton, 0, 0, 1, 1);
abortButton = new QPushButton(missionControlsFrame);
abortButton->setObjectName(QString::fromUtf8("abortButton"));
abortButton->setMinimumSize(QSize(80, 30));
abortButton->setMaximumSize(QSize(130, 50));
abortButton->setFont(font3);
abortButton->setLayoutDirection(Qt::LeftToRight);
abortButton->setAutoDefault(false);
abortButton->setFlat(false);
missionControlsGridLayout->addWidget(abortButton, 0, 1, 1, 1);
singleStepButton = new QPushButton(missionControlsFrame);
singleStepButton->setObjectName(QString::fromUtf8("singleStepButton"));
singleStepButton->setMinimumSize(QSize(80, 30));
singleStepButton->setMaximumSize(QSize(130, 50));
singleStepButton->setFont(font3);
missionControlsGridLayout->addWidget(singleStepButton, 1, 0, 1, 1);
autoButton = new QPushButton(missionControlsFrame);
autoButton->setObjectName(QString::fromUtf8("autoButton"));
autoButton->setMinimumSize(QSize(80, 30));
autoButton->setMaximumSize(QSize(130, 50));
autoButton->setFont(font3);
autoButton->setLayoutDirection(Qt::LeftToRight);
autoButton->setAutoDefault(false);
autoButton->setFlat(false);
missionControlsGridLayout->addWidget(autoButton, 1, 1, 1, 1);
pauseButton = new QPushButton(missionControlsFrame);
pauseButton->setObjectName(QString::fromUtf8("pauseButton"));
pauseButton->setMinimumSize(QSize(80, 30));
pauseButton->setMaximumSize(QSize(130, 50));
pauseButton->setFont(font3);
pauseButton->setLayoutDirection(Qt::LeftToRight);
pauseButton->setAutoDefault(false);
pauseButton->setFlat(false);
missionControlsGridLayout->addWidget(pauseButton, 2, 1, 1, 1);
verticalLayout->addLayout(missionControlsGridLayout);
gridLayout->addWidget(missionControlsFrame, 3, 1, 1, 1);
botControlsFrame = new QFrame(centralwidget);
botControlsFrame->setObjectName(QString::fromUtf8("botControlsFrame"));
QSizePolicy sizePolicy2(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy2.setHorizontalStretch(4);
sizePolicy2.setVerticalStretch(4);
sizePolicy2.setHeightForWidth(botControlsFrame->sizePolicy().hasHeightForWidth());
botControlsFrame->setSizePolicy(sizePolicy2);
botControlsFrame->setMinimumSize(QSize(160, 120));
botControlsFrame->setMaximumSize(QSize(320, 240));
botControlsFrame->setFrameShape(QFrame::WinPanel);
botControlsFrame->setFrameShadow(QFrame::Raised);
gridLayout_2 = new QGridLayout(botControlsFrame);
gridLayout_2->setObjectName(QString::fromUtf8("gridLayout_2"));
botControlsGridLayout = new QGridLayout();
botControlsGridLayout->setObjectName(QString::fromUtf8("botControlsGridLayout"));
botControlsGridLayout->setSizeConstraint(QLayout::SetMinimumSize);
downButton = new QPushButton(botControlsFrame);
downButton->setObjectName(QString::fromUtf8("downButton"));
downButton->setMinimumSize(QSize(30, 30));
downButton->setMaximumSize(QSize(50, 50));
downButton->setLayoutDirection(Qt::LeftToRight);
QIcon icon;
icon.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_unten.tga"), QSize(), QIcon::Normal, QIcon::Off);
downButton->setIcon(icon);
downButton->setIconSize(QSize(50, 50));
botControlsGridLayout->addWidget(downButton, 2, 1, 1, 1);
upButton = new QPushButton(botControlsFrame);
upButton->setObjectName(QString::fromUtf8("upButton"));
upButton->setMinimumSize(QSize(30, 30));
upButton->setMaximumSize(QSize(50, 50));
upButton->setSizeIncrement(QSize(0, 0));
QIcon icon1;
icon1.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_oben.tga"), QSize(), QIcon::Normal, QIcon::Off);
upButton->setIcon(icon1);
upButton->setIconSize(QSize(50, 50));
botControlsGridLayout->addWidget(upButton, 0, 1, 1, 1);
waitButton = new QPushButton(botControlsFrame);
waitButton->setObjectName(QString::fromUtf8("waitButton"));
waitButton->setMinimumSize(QSize(30, 30));
waitButton->setMaximumSize(QSize(50, 50));
QFont font4;
font4.setFamily(QString::fromUtf8("MS Shell Dlg 2"));
font4.setPointSize(15);
waitButton->setFont(font4);
waitButton->setContextMenuPolicy(Qt::DefaultContextMenu);
QIcon icon2;
QString iconThemeName = QString::fromUtf8("◀");
if (QIcon::hasThemeIcon(iconThemeName)) {
icon2 = QIcon::fromTheme(iconThemeName);
} else {
icon2.addFile(QString::fromUtf8("."), QSize(), QIcon::Normal, QIcon::Off);
}
waitButton->setIcon(icon2);
botControlsGridLayout->addWidget(waitButton, 1, 1, 1, 1);
leftButton = new QPushButton(botControlsFrame);
leftButton->setObjectName(QString::fromUtf8("leftButton"));
leftButton->setMinimumSize(QSize(30, 30));
leftButton->setMaximumSize(QSize(50, 50));
QIcon icon3;
icon3.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_links.tga"), QSize(), QIcon::Normal, QIcon::Off);
leftButton->setIcon(icon3);
leftButton->setIconSize(QSize(50, 50));
botControlsGridLayout->addWidget(leftButton, 1, 0, 1, 1);
deleteButton = new QPushButton(botControlsFrame);
deleteButton->setObjectName(QString::fromUtf8("deleteButton"));
deleteButton->setMinimumSize(QSize(30, 30));
deleteButton->setMaximumSize(QSize(50, 50));
QFont font5;
font5.setPointSize(15);
deleteButton->setFont(font5);
botControlsGridLayout->addWidget(deleteButton, 0, 2, 1, 1);
rightButton = new QPushButton(botControlsFrame);
rightButton->setObjectName(QString::fromUtf8("rightButton"));
rightButton->setMinimumSize(QSize(30, 30));
rightButton->setMaximumSize(QSize(50, 50));
rightButton->setSizeIncrement(QSize(0, 0));
QIcon icon4;
icon4.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_rechts.tga"), QSize(), QIcon::Normal, QIcon::Off);
rightButton->setIcon(icon4);
rightButton->setIconSize(QSize(50, 50));
botControlsGridLayout->addWidget(rightButton, 1, 2, 1, 1);
gridLayout_2->addLayout(botControlsGridLayout, 1, 0, 3, 1);
botControlsLabel = new QLabel(botControlsFrame);
botControlsLabel->setObjectName(QString::fromUtf8("botControlsLabel"));
botControlsLabel->setFont(font2);
botControlsLabel->setAlignment(Qt::AlignCenter);
gridLayout_2->addWidget(botControlsLabel, 0, 0, 1, 2);
repeatDropdown = new QComboBox(botControlsFrame);
repeatDropdown->addItem(QString());
repeatDropdown->addItem(QString());
repeatDropdown->addItem(QString());
repeatDropdown->addItem(QString());
repeatDropdown->addItem(QString());
repeatDropdown->setObjectName(QString::fromUtf8("repeatDropdown"));
repeatDropdown->setMinimumSize(QSize(80, 30));
repeatDropdown->setMaximumSize(QSize(130, 50));
QFont font6;
font6.setPointSize(15);
font6.setBold(true);
font6.setItalic(false);
font6.setWeight(75);
repeatDropdown->setFont(font6);
repeatDropdown->setFocusPolicy(Qt::WheelFocus);
repeatDropdown->setLayoutDirection(Qt::LeftToRight);
repeatDropdown->setInsertPolicy(QComboBox::NoInsert);
repeatDropdown->setFrame(true);
gridLayout_2->addWidget(repeatDropdown, 1, 1, 1, 1);
frame_6 = new QFrame(botControlsFrame);
frame_6->setObjectName(QString::fromUtf8("frame_6"));
frame_6->setFrameShape(QFrame::StyledPanel);
frame_6->setFrameShadow(QFrame::Raised);
gridLayout_2->addWidget(frame_6, 2, 1, 1, 1);
botCommandFrame = new QFrame(botControlsFrame);
botCommandFrame->setObjectName(QString::fromUtf8("botCommandFrame"));
botCommandFrame->setMinimumSize(QSize(100, 80));
botCommandFrame->setMaximumSize(QSize(130, 16777215));
botCommandFrame->setFrameShape(QFrame::StyledPanel);
botCommandFrame->setFrameShadow(QFrame::Raised);
botCommandTextEdit = new QTextEdit(botCommandFrame);
botCommandTextEdit->setObjectName(QString::fromUtf8("botCommandTextEdit"));
botCommandTextEdit->setGeometry(QRect(0, 16, 108, 50));
QSizePolicy sizePolicy3(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy3.setHorizontalStretch(130);
sizePolicy3.setVerticalStretch(50);
sizePolicy3.setHeightForWidth(botCommandTextEdit->sizePolicy().hasHeightForWidth());
botCommandTextEdit->setSizePolicy(sizePolicy3);
botCommandTextEdit->setMinimumSize(QSize(80, 30));
botCommandTextEdit->setMaximumSize(QSize(130, 50));
botCommandTextEdit->setFont(font5);
botCommandTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
botCommandTextEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
botCommandTextEdit->setLineWrapMode(QTextEdit::NoWrap);
botCommandTextEdit->setReadOnly(true);
gridLayout_2->addWidget(botCommandFrame, 3, 1, 1, 1);
gridLayout_2->setRowStretch(1, 2);
gridLayout_2->setRowStretch(2, 1);
gridLayout_2->setRowStretch(3, 1);
gridLayout->addWidget(botControlsFrame, 1, 1, 2, 1);
mapFrame = new QFrame(centralwidget);
mapFrame->setObjectName(QString::fromUtf8("mapFrame"));
QSizePolicy sizePolicy4(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
sizePolicy4.setHorizontalStretch(0);
sizePolicy4.setVerticalStretch(0);
sizePolicy4.setHeightForWidth(mapFrame->sizePolicy().hasHeightForWidth());
mapFrame->setSizePolicy(sizePolicy4);
mapFrame->setMinimumSize(QSize(120, 120));
mapFrame->setFrameShape(QFrame::StyledPanel);
mapFrame->setFrameShadow(QFrame::Raised);
gridLayout_6 = new QGridLayout(mapFrame);
gridLayout_6->setSpacing(0);
gridLayout_6->setObjectName(QString::fromUtf8("gridLayout_6"));
label = new QLabel(mapFrame);
label->setObjectName(QString::fromUtf8("label"));
sizePolicy4.setHeightForWidth(label->sizePolicy().hasHeightForWidth());
label->setSizePolicy(sizePolicy4);
label->setMinimumSize(QSize(0, 0));
label->setFrameShape(QFrame::Box);
label->setAlignment(Qt::AlignCenter);
gridLayout_6->addWidget(label, 0, 0, 1, 1);
verticalScrollBar = new QScrollBar(mapFrame);
verticalScrollBar->setObjectName(QString::fromUtf8("verticalScrollBar"));
verticalScrollBar->setOrientation(Qt::Vertical);
gridLayout_6->addWidget(verticalScrollBar, 0, 1, 1, 1);
horizontalScrollBar = new QScrollBar(mapFrame);
horizontalScrollBar->setObjectName(QString::fromUtf8("horizontalScrollBar"));
QSizePolicy sizePolicy5(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
sizePolicy5.setHorizontalStretch(0);
sizePolicy5.setVerticalStretch(0);
sizePolicy5.setHeightForWidth(horizontalScrollBar->sizePolicy().hasHeightForWidth());
horizontalScrollBar->setSizePolicy(sizePolicy5);
horizontalScrollBar->setOrientation(Qt::Horizontal);
gridLayout_6->addWidget(horizontalScrollBar, 1, 0, 1, 1);
gridLayout->addWidget(mapFrame, 1, 0, 3, 1);
gridLayout->setRowStretch(0, 1);
gridLayout->setRowStretch(1, 4);
gridLayout->setRowStretch(2, 4);
gridLayout->setColumnStretch(0, 2);
gridLayout->setColumnMinimumWidth(0, 1);
gridLayout->setColumnMinimumWidth(1, 1);
gridLayout->setRowMinimumHeight(0, 1);
gridLayout->setRowMinimumHeight(1, 1);
gridLayout->setRowMinimumHeight(2, 10);
gridLayout->setRowMinimumHeight(3, 1);
MainWindow->setCentralWidget(centralwidget);
menubar = new QMenuBar(MainWindow);
menubar->setObjectName(QString::fromUtf8("menubar"));
menubar->setGeometry(QRect(0, 0, 819, 20));
MainWindow->setMenuBar(menubar);
statusbar = new QStatusBar(MainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
retranslateUi(MainWindow);
abortButton->setDefault(false);
autoButton->setDefault(false);
pauseButton->setDefault(false);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "MainWindow", nullptr));
selectColonyButton->setText(QCoreApplication::translate("MainWindow", "Andere Kolonie ...", nullptr));
currentColonyLabel->setText(QCoreApplication::translate("MainWindow", "Aktuelle Kolonie: Lithium-Stollen 13-A", nullptr));
misisonControlsLabel->setText(QCoreApplication::translate("MainWindow", "Missionsablauf", nullptr));
startButton->setText(QCoreApplication::translate("MainWindow", "Start", nullptr));
abortButton->setText(QCoreApplication::translate("MainWindow", "Abbruch", nullptr));
singleStepButton->setText(QCoreApplication::translate("MainWindow", "Einzelschritt", nullptr));
autoButton->setText(QCoreApplication::translate("MainWindow", "Automatik", nullptr));
pauseButton->setText(QCoreApplication::translate("MainWindow", "Anhalten", nullptr));
downButton->setText(QString());
upButton->setText(QString());
waitButton->setText(QCoreApplication::translate("MainWindow", "W", nullptr));
leftButton->setText(QString());
deleteButton->setText(QCoreApplication::translate("MainWindow", "<", nullptr));
rightButton->setText(QString());
botControlsLabel->setText(QCoreApplication::translate("MainWindow", "Programmieren", nullptr));
repeatDropdown->setItemText(0, QCoreApplication::translate("MainWindow", "1", nullptr));
repeatDropdown->setItemText(1, QCoreApplication::translate("MainWindow", "2", nullptr));
repeatDropdown->setItemText(2, QCoreApplication::translate("MainWindow", "3", nullptr));
repeatDropdown->setItemText(3, QCoreApplication::translate("MainWindow", "4", nullptr));
repeatDropdown->setItemText(4, QCoreApplication::translate("MainWindow", "5", nullptr));
repeatDropdown->setCurrentText(QCoreApplication::translate("MainWindow", "1", nullptr));
botCommandTextEdit->setPlaceholderText(QCoreApplication::translate("MainWindow", "Textfeld", nullptr));
label->setText(QCoreApplication::translate("MainWindow", "Umgebungskarte", nullptr));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // PATCHBOT_GUI_H
main file (from Qt Designer):
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
other files (from Qt Designer):
mainwindow.cpp (to customize my buttons):
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QMessageBox"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_upButton_clicked()
{
QMessageBox::information(this, "button", "up");
}
void MainWindow::on_rightButton_clicked()
{
QMessageBox::information(this, "button", "right");
}
void MainWindow::on_downButton_clicked()
{
QMessageBox::information(this, "button", "down");
}
void MainWindow::on_leftButton_clicked()
{
QMessageBox::information(this, "button", "left");
}
void MainWindow::on_waitButton_clicked()
{
QMessageBox::information(this, "button", "wait");
}
void MainWindow::on_deleteButton_clicked()
{
QMessageBox::information(this, "button", "delete");
}
void MainWindow::on_selectColonyButton_clicked()
{
QMessageBox::information(this, "button", ui->selectColonyButton->text());
}
void MainWindow::on_startButton_clicked()
{
QMessageBox::information(this, "button", ui->startButton->text());
}
void MainWindow::on_abortButton_clicked()
{
QMessageBox::information(this, "button", ui->abortButton->text());
}
void MainWindow::on_singleStepButton_clicked()
{
QMessageBox::information(this, "button", ui->singleStepButton->text());
}
void MainWindow::on_autoButton_clicked()
{
QMessageBox::information(this, "button", ui->autoButton->text());
}
void MainWindow::on_pauseButton_clicked()
{
QMessageBox::information(this, "button", ui->pauseButton->text());
}
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_upButton_clicked();
void on_rightButton_clicked();
void on_downButton_clicked();
void on_leftButton_clicked();
void on_waitButton_clicked();
void on_deleteButton_clicked();
void on_selectColonyButton_clicked();
void on_startButton_clicked();
void on_abortButton_clicked();
void on_singleStepButton_clicked();
void on_autoButton_clicked();
void on_pauseButton_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
If further information is needed, I'd be happy to help.
Related
I am using QGridLayout, the first row has a QLabel which is used to show an icon set to 32x32 pixels. The next row has two QSvgWidgets, each of these is 16x14.
My code:
QGridLayout* pgrdloStatus(new QGridLayout);
if ( mplblStsIcon == nullptr )
{
mplblStsIcon = new QLabel();
}
if ( mpsvgRxIcon == nullptr )
{
mpsvgRxIcon = new QSvgWidget(":/SVG_LED");
mpsvgRxIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
mpsvgRxIcon->setFixedSize(TraineeMonitor::mscuintCommsIconWidth,
TraineeMonitor::mscuintCommsIconHeight);
}
if ( mpsvgTxIcon == nullptr )
{
mpsvgTxIcon = new QSvgWidget(":/SVG_LED");
mpsvgTxIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
mpsvgTxIcon->setFixedSize(TraineeMonitor::mscuintCommsIconWidth,
TraineeMonitor::mscuintCommsIconHeight);
}
const QString cstrToolTip(QString(
" %1: %2\r\n%3: %4")
.arg(tr("Hostname:")).arg(mstrHostname)
.arg(tr("MAC address:")).arg(mstrMACaddress));
mplblStsIcon->setToolTip(cstrToolTip);
pgrdloStatus->addWidget(mplblStsIcon, 0, 0, 1, 2, Qt::AlignHCenter);
pgrdloStatus->addWidget(mpsvgRxIcon, 1, 0, Qt::AlignLeft);
pgrdloStatus->addWidget(mpsvgTxIcon, 1, 1, Qt::AlignRight);
pgrdloStatus->setMargin(0);
pgrdloStatus->setSpacing(0);
return pgrdloStatus;
The result:
What I actually want is:
I create this Example and add Items From the Designer to show you why you see that distance between icons.
I create GridLayout and put 2 labels and set 2 LED SVG image
this is what actually you do too :
But For Fixing this issue you should check this property :
which means this : label->setScaledContents(true);
Which means that your icons match to labels.
For removing margins of GridLay out you can also do this :
This is its code:
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *centralwidget;
QGridLayout *gridLayout;
QLabel *label;
QLabel *label_2;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(207, 109);
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
gridLayout = new QGridLayout(centralwidget);
gridLayout->setSpacing(0);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
gridLayout->setContentsMargins(0, 0, 0, 0);
label = new QLabel(centralwidget);
label->setObjectName(QString::fromUtf8("label"));
label->setPixmap(QPixmap(QString::fromUtf8(":/icons/led-square-red.svg")));
label->setScaledContents(true);
gridLayout->addWidget(label, 0, 0, 1, 1);
label_2 = new QLabel(centralwidget);
label_2->setObjectName(QString::fromUtf8("label_2"));
label_2->setPixmap(QPixmap(QString::fromUtf8(":/icons/led-square-red.svg")));
label_2->setScaledContents(true);
gridLayout->addWidget(label_2, 0, 1, 1, 1);
MainWindow->setCentralWidget(centralwidget);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "MainWindow", nullptr));
label->setText(QString());
label_2->setText(QString());
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H
I converted my .ui file via uic into a header file, which, as far as I know, contains the header AND the implementation of the .ui file.
But what part of it is the header and what is the implementation?
Is there a way to seperate them properly?
#ifndef PATCHBOT_GUI_H
#define PATCHBOT_GUI_H
#include <QtCore/QVariant>
#include <QtGui/QIcon>
#include <QtWidgets/QApplication>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QFrame>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QScrollBar>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *centralwidget;
QGridLayout *gridLayout;
QFrame *selectColonyFrame;
QPushButton *selectColonyButton;
QFrame *currentColonyFrame;
QLabel *currentColonyLabel;
QFrame *missionControlsFrame;
QVBoxLayout *verticalLayout;
QLabel *misisonControlsLabel;
QGridLayout *missionControlsGridLayout;
QPushButton *startButton;
QPushButton *abortButton;
QPushButton *singleStepButton;
QPushButton *autoButton;
QPushButton *pauseButton;
QFrame *botControlsFrame;
QGridLayout *gridLayout_2;
QGridLayout *botControlsGridLayout;
QPushButton *downButton;
QPushButton *upButton;
QPushButton *waitButton;
QPushButton *leftButton;
QPushButton *deleteButton;
QPushButton *rightButton;
QLabel *botControlsLabel;
QComboBox *repeatDropdown;
QFrame *frame_6;
QFrame *botCommandFrame;
QTextEdit *botCommandTextEdit;
QFrame *mapFrame;
QGridLayout *gridLayout_6;
QLabel *label;
QScrollBar *verticalScrollBar;
QScrollBar *horizontalScrollBar;
QMenuBar *menubar;
QStatusBar *statusbar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(819, 634);
MainWindow->setMinimumSize(QSize(580, 400));
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
gridLayout = new QGridLayout(centralwidget);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
gridLayout->setVerticalSpacing(6);
gridLayout->setContentsMargins(-1, 0, -1, 0);
selectColonyFrame = new QFrame(centralwidget);
selectColonyFrame->setObjectName(QString::fromUtf8("selectColonyFrame"));
selectColonyFrame->setMinimumSize(QSize(150, 40));
selectColonyFrame->setLayoutDirection(Qt::RightToLeft);
selectColonyFrame->setFrameShape(QFrame::StyledPanel);
selectColonyFrame->setFrameShadow(QFrame::Raised);
selectColonyButton = new QPushButton(selectColonyFrame);
selectColonyButton->setObjectName(QString::fromUtf8("selectColonyButton"));
selectColonyButton->setGeometry(QRect(80, 0, 150, 40));
selectColonyButton->setMinimumSize(QSize(150, 40));
selectColonyButton->setMaximumSize(QSize(150, 50));
QFont font;
font.setPointSize(11);
font.setBold(true);
font.setWeight(75);
selectColonyButton->setFont(font);
gridLayout->addWidget(selectColonyFrame, 0, 1, 1, 1);
currentColonyFrame = new QFrame(centralwidget);
currentColonyFrame->setObjectName(QString::fromUtf8("currentColonyFrame"));
QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(currentColonyFrame->sizePolicy().hasHeightForWidth());
currentColonyFrame->setSizePolicy(sizePolicy);
currentColonyFrame->setMinimumSize(QSize(0, 25));
currentColonyFrame->setFrameShape(QFrame::StyledPanel);
currentColonyFrame->setFrameShadow(QFrame::Raised);
currentColonyLabel = new QLabel(currentColonyFrame);
currentColonyLabel->setObjectName(QString::fromUtf8("currentColonyLabel"));
currentColonyLabel->setGeometry(QRect(10, 10, 301, 16));
currentColonyLabel->setMinimumSize(QSize(220, 15));
currentColonyLabel->setMaximumSize(QSize(460, 25));
QFont font1;
font1.setPointSize(10);
currentColonyLabel->setFont(font1);
gridLayout->addWidget(currentColonyFrame, 0, 0, 1, 1);
missionControlsFrame = new QFrame(centralwidget);
missionControlsFrame->setObjectName(QString::fromUtf8("missionControlsFrame"));
QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy1.setHorizontalStretch(8);
sizePolicy1.setVerticalStretch(8);
sizePolicy1.setHeightForWidth(missionControlsFrame->sizePolicy().hasHeightForWidth());
missionControlsFrame->setSizePolicy(sizePolicy1);
missionControlsFrame->setMaximumSize(QSize(300, 180));
missionControlsFrame->setFrameShape(QFrame::WinPanel);
missionControlsFrame->setFrameShadow(QFrame::Raised);
verticalLayout = new QVBoxLayout(missionControlsFrame);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
misisonControlsLabel = new QLabel(missionControlsFrame);
misisonControlsLabel->setObjectName(QString::fromUtf8("misisonControlsLabel"));
QFont font2;
font2.setPointSize(11);
misisonControlsLabel->setFont(font2);
misisonControlsLabel->setAlignment(Qt::AlignCenter);
verticalLayout->addWidget(misisonControlsLabel);
missionControlsGridLayout = new QGridLayout();
missionControlsGridLayout->setObjectName(QString::fromUtf8("missionControlsGridLayout"));
missionControlsGridLayout->setHorizontalSpacing(20);
missionControlsGridLayout->setVerticalSpacing(10);
missionControlsGridLayout->setContentsMargins(15, 20, 15, 0);
startButton = new QPushButton(missionControlsFrame);
startButton->setObjectName(QString::fromUtf8("startButton"));
startButton->setMinimumSize(QSize(80, 30));
startButton->setMaximumSize(QSize(130, 50));
QFont font3;
font3.setPointSize(12);
startButton->setFont(font3);
missionControlsGridLayout->addWidget(startButton, 0, 0, 1, 1);
abortButton = new QPushButton(missionControlsFrame);
abortButton->setObjectName(QString::fromUtf8("abortButton"));
abortButton->setMinimumSize(QSize(80, 30));
abortButton->setMaximumSize(QSize(130, 50));
abortButton->setFont(font3);
abortButton->setLayoutDirection(Qt::LeftToRight);
abortButton->setAutoDefault(false);
abortButton->setFlat(false);
missionControlsGridLayout->addWidget(abortButton, 0, 1, 1, 1);
singleStepButton = new QPushButton(missionControlsFrame);
singleStepButton->setObjectName(QString::fromUtf8("singleStepButton"));
singleStepButton->setMinimumSize(QSize(80, 30));
singleStepButton->setMaximumSize(QSize(130, 50));
singleStepButton->setFont(font3);
missionControlsGridLayout->addWidget(singleStepButton, 1, 0, 1, 1);
autoButton = new QPushButton(missionControlsFrame);
autoButton->setObjectName(QString::fromUtf8("autoButton"));
autoButton->setMinimumSize(QSize(80, 30));
autoButton->setMaximumSize(QSize(130, 50));
autoButton->setFont(font3);
autoButton->setLayoutDirection(Qt::LeftToRight);
autoButton->setAutoDefault(false);
autoButton->setFlat(false);
missionControlsGridLayout->addWidget(autoButton, 1, 1, 1, 1);
pauseButton = new QPushButton(missionControlsFrame);
pauseButton->setObjectName(QString::fromUtf8("pauseButton"));
pauseButton->setMinimumSize(QSize(80, 30));
pauseButton->setMaximumSize(QSize(130, 50));
pauseButton->setFont(font3);
pauseButton->setLayoutDirection(Qt::LeftToRight);
pauseButton->setAutoDefault(false);
pauseButton->setFlat(false);
missionControlsGridLayout->addWidget(pauseButton, 2, 1, 1, 1);
verticalLayout->addLayout(missionControlsGridLayout);
gridLayout->addWidget(missionControlsFrame, 3, 1, 1, 1);
botControlsFrame = new QFrame(centralwidget);
botControlsFrame->setObjectName(QString::fromUtf8("botControlsFrame"));
QSizePolicy sizePolicy2(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy2.setHorizontalStretch(4);
sizePolicy2.setVerticalStretch(4);
sizePolicy2.setHeightForWidth(botControlsFrame->sizePolicy().hasHeightForWidth());
botControlsFrame->setSizePolicy(sizePolicy2);
botControlsFrame->setMinimumSize(QSize(160, 120));
botControlsFrame->setMaximumSize(QSize(320, 240));
botControlsFrame->setFrameShape(QFrame::WinPanel);
botControlsFrame->setFrameShadow(QFrame::Raised);
gridLayout_2 = new QGridLayout(botControlsFrame);
gridLayout_2->setObjectName(QString::fromUtf8("gridLayout_2"));
botControlsGridLayout = new QGridLayout();
botControlsGridLayout->setObjectName(QString::fromUtf8("botControlsGridLayout"));
botControlsGridLayout->setSizeConstraint(QLayout::SetMinimumSize);
downButton = new QPushButton(botControlsFrame);
downButton->setObjectName(QString::fromUtf8("downButton"));
downButton->setMinimumSize(QSize(30, 30));
downButton->setMaximumSize(QSize(50, 50));
downButton->setLayoutDirection(Qt::LeftToRight);
QIcon icon;
icon.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_unten.tga"), QSize(), QIcon::Normal, QIcon::Off);
downButton->setIcon(icon);
downButton->setIconSize(QSize(50, 50));
botControlsGridLayout->addWidget(downButton, 2, 1, 1, 1);
upButton = new QPushButton(botControlsFrame);
upButton->setObjectName(QString::fromUtf8("upButton"));
upButton->setMinimumSize(QSize(30, 30));
upButton->setMaximumSize(QSize(50, 50));
upButton->setSizeIncrement(QSize(0, 0));
QIcon icon1;
icon1.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_oben.tga"), QSize(), QIcon::Normal, QIcon::Off);
upButton->setIcon(icon1);
upButton->setIconSize(QSize(50, 50));
botControlsGridLayout->addWidget(upButton, 0, 1, 1, 1);
waitButton = new QPushButton(botControlsFrame);
waitButton->setObjectName(QString::fromUtf8("waitButton"));
waitButton->setMinimumSize(QSize(30, 30));
waitButton->setMaximumSize(QSize(50, 50));
QFont font4;
font4.setFamily(QString::fromUtf8("MS Shell Dlg 2"));
font4.setPointSize(15);
waitButton->setFont(font4);
waitButton->setContextMenuPolicy(Qt::DefaultContextMenu);
QIcon icon2;
QString iconThemeName = QString::fromUtf8("◀");
if (QIcon::hasThemeIcon(iconThemeName)) {
icon2 = QIcon::fromTheme(iconThemeName);
} else {
icon2.addFile(QString::fromUtf8("."), QSize(), QIcon::Normal, QIcon::Off);
}
waitButton->setIcon(icon2);
botControlsGridLayout->addWidget(waitButton, 1, 1, 1, 1);
leftButton = new QPushButton(botControlsFrame);
leftButton->setObjectName(QString::fromUtf8("leftButton"));
leftButton->setMinimumSize(QSize(30, 30));
leftButton->setMaximumSize(QSize(50, 50));
QIcon icon3;
icon3.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_links.tga"), QSize(), QIcon::Normal, QIcon::Off);
leftButton->setIcon(icon3);
leftButton->setIconSize(QSize(50, 50));
botControlsGridLayout->addWidget(leftButton, 1, 0, 1, 1);
deleteButton = new QPushButton(botControlsFrame);
deleteButton->setObjectName(QString::fromUtf8("deleteButton"));
deleteButton->setMinimumSize(QSize(30, 30));
deleteButton->setMaximumSize(QSize(50, 50));
QFont font5;
font5.setPointSize(15);
deleteButton->setFont(font5);
botControlsGridLayout->addWidget(deleteButton, 0, 2, 1, 1);
rightButton = new QPushButton(botControlsFrame);
rightButton->setObjectName(QString::fromUtf8("rightButton"));
rightButton->setMinimumSize(QSize(30, 30));
rightButton->setMaximumSize(QSize(50, 50));
rightButton->setSizeIncrement(QSize(0, 0));
QIcon icon4;
icon4.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_rechts.tga"), QSize(), QIcon::Normal, QIcon::Off);
rightButton->setIcon(icon4);
rightButton->setIconSize(QSize(50, 50));
botControlsGridLayout->addWidget(rightButton, 1, 2, 1, 1);
gridLayout_2->addLayout(botControlsGridLayout, 1, 0, 3, 1);
botControlsLabel = new QLabel(botControlsFrame);
botControlsLabel->setObjectName(QString::fromUtf8("botControlsLabel"));
botControlsLabel->setFont(font2);
botControlsLabel->setAlignment(Qt::AlignCenter);
gridLayout_2->addWidget(botControlsLabel, 0, 0, 1, 2);
repeatDropdown = new QComboBox(botControlsFrame);
repeatDropdown->addItem(QString());
repeatDropdown->addItem(QString());
repeatDropdown->addItem(QString());
repeatDropdown->addItem(QString());
repeatDropdown->addItem(QString());
repeatDropdown->setObjectName(QString::fromUtf8("repeatDropdown"));
repeatDropdown->setMinimumSize(QSize(80, 30));
repeatDropdown->setMaximumSize(QSize(130, 50));
QFont font6;
font6.setPointSize(15);
font6.setBold(true);
font6.setItalic(false);
font6.setWeight(75);
repeatDropdown->setFont(font6);
repeatDropdown->setFocusPolicy(Qt::WheelFocus);
repeatDropdown->setLayoutDirection(Qt::LeftToRight);
repeatDropdown->setInsertPolicy(QComboBox::NoInsert);
repeatDropdown->setFrame(true);
gridLayout_2->addWidget(repeatDropdown, 1, 1, 1, 1);
frame_6 = new QFrame(botControlsFrame);
frame_6->setObjectName(QString::fromUtf8("frame_6"));
frame_6->setFrameShape(QFrame::StyledPanel);
frame_6->setFrameShadow(QFrame::Raised);
gridLayout_2->addWidget(frame_6, 2, 1, 1, 1);
botCommandFrame = new QFrame(botControlsFrame);
botCommandFrame->setObjectName(QString::fromUtf8("botCommandFrame"));
botCommandFrame->setMinimumSize(QSize(100, 80));
botCommandFrame->setMaximumSize(QSize(130, 16777215));
botCommandFrame->setFrameShape(QFrame::StyledPanel);
botCommandFrame->setFrameShadow(QFrame::Raised);
botCommandTextEdit = new QTextEdit(botCommandFrame);
botCommandTextEdit->setObjectName(QString::fromUtf8("botCommandTextEdit"));
botCommandTextEdit->setGeometry(QRect(0, 16, 108, 50));
QSizePolicy sizePolicy3(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy3.setHorizontalStretch(130);
sizePolicy3.setVerticalStretch(50);
sizePolicy3.setHeightForWidth(botCommandTextEdit->sizePolicy().hasHeightForWidth());
botCommandTextEdit->setSizePolicy(sizePolicy3);
botCommandTextEdit->setMinimumSize(QSize(80, 30));
botCommandTextEdit->setMaximumSize(QSize(130, 50));
botCommandTextEdit->setFont(font5);
botCommandTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
botCommandTextEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
botCommandTextEdit->setLineWrapMode(QTextEdit::NoWrap);
botCommandTextEdit->setReadOnly(true);
gridLayout_2->addWidget(botCommandFrame, 3, 1, 1, 1);
gridLayout_2->setRowStretch(1, 2);
gridLayout_2->setRowStretch(2, 1);
gridLayout_2->setRowStretch(3, 1);
gridLayout->addWidget(botControlsFrame, 1, 1, 2, 1);
mapFrame = new QFrame(centralwidget);
mapFrame->setObjectName(QString::fromUtf8("mapFrame"));
QSizePolicy sizePolicy4(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
sizePolicy4.setHorizontalStretch(0);
sizePolicy4.setVerticalStretch(0);
sizePolicy4.setHeightForWidth(mapFrame->sizePolicy().hasHeightForWidth());
mapFrame->setSizePolicy(sizePolicy4);
mapFrame->setMinimumSize(QSize(120, 120));
mapFrame->setFrameShape(QFrame::StyledPanel);
mapFrame->setFrameShadow(QFrame::Raised);
gridLayout_6 = new QGridLayout(mapFrame);
gridLayout_6->setSpacing(0);
gridLayout_6->setObjectName(QString::fromUtf8("gridLayout_6"));
label = new QLabel(mapFrame);
label->setObjectName(QString::fromUtf8("label"));
sizePolicy4.setHeightForWidth(label->sizePolicy().hasHeightForWidth());
label->setSizePolicy(sizePolicy4);
label->setMinimumSize(QSize(0, 0));
label->setFrameShape(QFrame::Box);
label->setAlignment(Qt::AlignCenter);
gridLayout_6->addWidget(label, 0, 0, 1, 1);
verticalScrollBar = new QScrollBar(mapFrame);
verticalScrollBar->setObjectName(QString::fromUtf8("verticalScrollBar"));
verticalScrollBar->setOrientation(Qt::Vertical);
gridLayout_6->addWidget(verticalScrollBar, 0, 1, 1, 1);
horizontalScrollBar = new QScrollBar(mapFrame);
horizontalScrollBar->setObjectName(QString::fromUtf8("horizontalScrollBar"));
QSizePolicy sizePolicy5(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
sizePolicy5.setHorizontalStretch(0);
sizePolicy5.setVerticalStretch(0);
sizePolicy5.setHeightForWidth(horizontalScrollBar->sizePolicy().hasHeightForWidth());
horizontalScrollBar->setSizePolicy(sizePolicy5);
horizontalScrollBar->setOrientation(Qt::Horizontal);
gridLayout_6->addWidget(horizontalScrollBar, 1, 0, 1, 1);
gridLayout->addWidget(mapFrame, 1, 0, 3, 1);
gridLayout->setRowStretch(0, 1);
gridLayout->setRowStretch(1, 4);
gridLayout->setRowStretch(2, 4);
gridLayout->setColumnStretch(0, 2);
gridLayout->setColumnMinimumWidth(0, 1);
gridLayout->setColumnMinimumWidth(1, 1);
gridLayout->setRowMinimumHeight(0, 1);
gridLayout->setRowMinimumHeight(1, 1);
gridLayout->setRowMinimumHeight(2, 10);
gridLayout->setRowMinimumHeight(3, 1);
MainWindow->setCentralWidget(centralwidget);
menubar = new QMenuBar(MainWindow);
menubar->setObjectName(QString::fromUtf8("menubar"));
menubar->setGeometry(QRect(0, 0, 819, 20));
MainWindow->setMenuBar(menubar);
statusbar = new QStatusBar(MainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
retranslateUi(MainWindow);
abortButton->setDefault(false);
autoButton->setDefault(false);
pauseButton->setDefault(false);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "MainWindow", nullptr));
selectColonyButton->setText(QCoreApplication::translate("MainWindow", "Andere Kolonie ...", nullptr));
currentColonyLabel->setText(QCoreApplication::translate("MainWindow", "Aktuelle Kolonie: Lithium-Stollen 13-A", nullptr));
misisonControlsLabel->setText(QCoreApplication::translate("MainWindow", "Missionsablauf", nullptr));
startButton->setText(QCoreApplication::translate("MainWindow", "Start", nullptr));
abortButton->setText(QCoreApplication::translate("MainWindow", "Abbruch", nullptr));
singleStepButton->setText(QCoreApplication::translate("MainWindow", "Einzelschritt", nullptr));
autoButton->setText(QCoreApplication::translate("MainWindow", "Automatik", nullptr));
pauseButton->setText(QCoreApplication::translate("MainWindow", "Anhalten", nullptr));
downButton->setText(QString());
upButton->setText(QString());
waitButton->setText(QCoreApplication::translate("MainWindow", "W", nullptr));
leftButton->setText(QString());
deleteButton->setText(QCoreApplication::translate("MainWindow", "<", nullptr));
rightButton->setText(QString());
botControlsLabel->setText(QCoreApplication::translate("MainWindow", "Programmieren", nullptr));
repeatDropdown->setItemText(0, QCoreApplication::translate("MainWindow", "1", nullptr));
repeatDropdown->setItemText(1, QCoreApplication::translate("MainWindow", "2", nullptr));
repeatDropdown->setItemText(2, QCoreApplication::translate("MainWindow", "3", nullptr));
repeatDropdown->setItemText(3, QCoreApplication::translate("MainWindow", "4", nullptr));
repeatDropdown->setItemText(4, QCoreApplication::translate("MainWindow", "5", nullptr));
repeatDropdown->setCurrentText(QCoreApplication::translate("MainWindow", "1", nullptr));
botCommandTextEdit->setPlaceholderText(QCoreApplication::translate("MainWindow", "Textfeld", nullptr));
label->setText(QCoreApplication::translate("MainWindow", "Umgebungskarte", nullptr));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // PATCHBOT_GUI_H
Since I'm working with VS 2019 and have the "QT VS Tools" extension installed, I could also use the new "Convert Project to Qmake generated Project" tool. The problem here is, that I don't really know how it works.
I opened my .pro file from Qt Designer with the "Open Qt project file..." funciton and then used the tool mentioned above. After the process finished, I didn't see any changes or new files. Did I miss something? Do I need to do something else?
If further information is needed, I'd be happy to help.
Basically the minimal Qt stand-alone example is two source files, one header file, and the UI XML file:
There's the "main" Source file which contains the main function
There's a "main window" source file which contains the implementation for the main window
There's the "main window" header file
And as mentioned there's the UI XML file
The "main" source file could be very simple, all it does is create a QApplication object and the MainWindow object. It shows the main window and then enters the application event loop:
#include <QApplication>
#include "MainWindow.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
MainWindow window;
window.show(); // Show the main window
return app.exec(); // Run the application event loop
}
The "main window" header file start out also very simple:
#include <QMainWindow>
namespace Ui
{
class MainWindow; // This is the "main window" from the UI XML file
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget* parent = nullptr);
~MainWindow();
private:
Ui::MainWindow* ui; // Pointer to the UI generated by the XML file and the uic program
};
And finally the "main window" implementation source file:
#include "MainWindow.h"
#include "ui_mainwindow.h" // This is the automatically generated header file created by uic
MainWindow::MainWindow(QWidget* parent /* = nullptr */)
: QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
You also need to run the uic program to generate the needed source files from the UI XML file, and then build with the source file. You also need to use the moc tool to resolve slots and signals.
All of this should really be in most tutorials you will find online.
What I want to do is that it give me a list with all .cpp files in the Directory and the Subdirectories. Problem it.HasNext stay on false and also it.filePath stay empty.
main.cpp
#include "QtSignal_Slot.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QtSignal_Slot w;
w.show();
return a.exec();
}
ui_QtSignal_Slot.h
#ifndef UI_QTSIGNAL_SLOT_H
#define UI_QTSIGNAL_SLOT_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QToolBar>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_QtSignal_SlotClass
{
public:
QWidget *centralWidget;
QGridLayout *gridLayout;
QPushButton *ButtonStart;
QSpacerItem *horizontalSpacer_2;
QSpacerItem *horizontalSpacer_4;
QTextEdit *textEdit;
QSpacerItem *verticalSpacer_2;
QSpacerItem *verticalSpacer_3;
QSpacerItem *horizontalSpacer;
QSpacerItem *horizontalSpacer_3;
QLineEdit *PathEdit;
QMenuBar *menuBar;
QToolBar *mainToolBar;
QStatusBar *statusBar;
void setupUi(QMainWindow *QtSignal_SlotClass)
{
if (QtSignal_SlotClass->objectName().isEmpty())
QtSignal_SlotClass->setObjectName(QStringLiteral("QtSignal_SlotClass"));
QtSignal_SlotClass->setEnabled(true);
QtSignal_SlotClass->resize(380, 250);
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(QtSignal_SlotClass->sizePolicy().hasHeightForWidth());
QtSignal_SlotClass->setSizePolicy(sizePolicy);
QtSignal_SlotClass->setMinimumSize(QSize(380, 250));
QtSignal_SlotClass->setMaximumSize(QSize(700, 300));
QtSignal_SlotClass->setSizeIncrement(QSize(400, 250));
QtSignal_SlotClass->setBaseSize(QSize(200, 250));
centralWidget = new QWidget(QtSignal_SlotClass);
centralWidget->setObjectName(QStringLiteral("centralWidget"));
gridLayout = new QGridLayout(centralWidget);
gridLayout->setSpacing(6);
gridLayout->setContentsMargins(11, 11, 11, 11);
gridLayout->setObjectName(QStringLiteral("gridLayout"));
ButtonStart = new QPushButton(centralWidget);
ButtonStart->setObjectName(QStringLiteral("ButtonStart"));
ButtonStart->setStyleSheet(QStringLiteral("background-color: rgb(200,200,255); color: rgb(0,0,0);"));
gridLayout->addWidget(ButtonStart, 7, 1, 1, 1);
horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout->addItem(horizontalSpacer_2, 7, 2, 1, 1);
horizontalSpacer_4 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout->addItem(horizontalSpacer_4, 0, 2, 1, 1);
textEdit = new QTextEdit(centralWidget);
textEdit->setObjectName(QStringLiteral("textEdit"));
textEdit->setStyleSheet(QStringLiteral("color: rgb(0,0,0);"));
gridLayout->addWidget(textEdit, 3, 1, 1, 1);
verticalSpacer_2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
gridLayout->addItem(verticalSpacer_2, 1, 1, 1, 1);
verticalSpacer_3 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
gridLayout->addItem(verticalSpacer_3, 2, 1, 1, 1);
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout->addItem(horizontalSpacer, 7, 0, 1, 1);
horizontalSpacer_3 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout->addItem(horizontalSpacer_3, 0, 0, 1, 1);
PathEdit = new QLineEdit(centralWidget);
PathEdit->setObjectName(QStringLiteral("PathEdit"));
QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Preferred);
sizePolicy1.setHorizontalStretch(0);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(PathEdit->sizePolicy().hasHeightForWidth());
PathEdit->setSizePolicy(sizePolicy1);
PathEdit->setMinimumSize(QSize(200, 30));
PathEdit->setStyleSheet(QStringLiteral("background-color: rgb(240,240,240); color: rgb(0,0,0);"));
gridLayout->addWidget(PathEdit, 0, 1, 1, 1);
QtSignal_SlotClass->setCentralWidget(centralWidget);
menuBar = new QMenuBar(QtSignal_SlotClass);
menuBar->setObjectName(QStringLiteral("menuBar"));
menuBar->setGeometry(QRect(0, 0, 380, 21));
QtSignal_SlotClass->setMenuBar(menuBar);
mainToolBar = new QToolBar(QtSignal_SlotClass);
mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
QtSignal_SlotClass->addToolBar(Qt::TopToolBarArea, mainToolBar);
statusBar = new QStatusBar(QtSignal_SlotClass);
statusBar->setObjectName(QStringLiteral("statusBar"));
QtSignal_SlotClass->setStatusBar(statusBar);
retranslateUi(QtSignal_SlotClass);
QMetaObject::connectSlotsByName(QtSignal_SlotClass);
} // setupUi
void retranslateUi(QMainWindow *QtSignal_SlotClass)
{
QtSignal_SlotClass->setWindowTitle(QApplication::translate("QtSignal_SlotClass", "QtSignal_Slot", Q_NULLPTR));
ButtonStart->setText(QApplication::translate("QtSignal_SlotClass", "Generate graphicfile", Q_NULLPTR));
PathEdit->setText(QString());
} // retranslateUi
};
namespace Ui {
class QtSignal_SlotClass: public Ui_QtSignal_SlotClass {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_QTSIGNAL_SLOT_H
QtSignal_Slot.h
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_QtSignal_Slot.h"
class QtSignal_Slot : public QMainWindow
{
Q_OBJECT
public:
QString m_Path;
QtSignal_Slot(QWidget *parent = Q_NULLPTR);
public slots:
void m_StartButtonpressed();
private:
Ui::QtSignal_SlotClass ui;
};
QtSolts_Signel.cpp
#include "QtSignal_Slot.h"
#include <ui_QtSignal_Slot.h>
#include <QDirIterator>
#include <QDebug>
QtSignal_Slot::QtSignal_Slot(QWidget *parent) : QMainWindow(nullptr)
{
ui.setupUi(this);
connect(ui.ButtonStart, SIGNAL(clicked()), this, SLOT(m_StartButtonpressed()));
}
void QtSignal_Slot::m_StartButton()
{
m_Path = (ui.PathEdit->text());
QDirIterator it(m_Path, QStringList() << "*.cpp" , QDir::Files, QDirIterator::Subdirectories);
do
{
qDebug() << it.next();
} while (it.hasNext());
qDebug() << "This, show in the Output";
QString Buffer = QString("%1").arg(QString::number(it.hasNext()));
ui.textEdit->setText(Buffer +"->" + it.filePath() + "<-" + m_Path);
}
The output in the textEdit is:
"0-> <-(correct path i but i as input)"
and output in the debug-output is:
" ' ' , This, show in the Output"
The code is updated, but the problem stays.
Example
Here is an example of how to make the slot work:
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QLineEdit;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
private:
QLineEdit *m_pathEdit;
QLineEdit *m_textEdit;
private slots:
void onButtonClicked();
};
#endif // MAINWINDOW_H
MainWindow.cpp
#include "MainWindow.h"
#include <QDirIterator>
#include <QBoxLayout>
#include <QPushButton>
#include <QLineEdit>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
m_pathEdit(new QLineEdit(this)),
m_textEdit(new QLineEdit(this))
{
auto *widget = new QWidget(this);
auto *layoutMain = new QVBoxLayout(widget);
auto *button = new QPushButton(tr("Click me"), this);
layoutMain->addWidget(m_pathEdit);
layoutMain->addWidget(m_textEdit);
layoutMain->addWidget(button);
setCentralWidget(widget);
connect(button, &QPushButton::clicked, this, &MainWindow::onButtonClicked);
}
void MainWindow::onButtonClicked()
{
const QString &path(m_pathEdit->text());
QDirIterator it(path, QStringList() << "*.cpp" , QDir::Files, QDirIterator::Subdirectories);
do
{
qDebug() << it.next();
} while (it.hasNext());
qDebug() << "This, show in the Output";
QString buffer(QString("%1").arg(QString::number(it.hasNext())));
m_textEdit->setText(buffer +"->" + it.filePath() + "<-" + path);
}
Result
For the following input (entered in m_pathEdit, the upper QLineEdit):
/Users/Michael Scopchanov/Desktop/untitled9/
the result in the console is:
"/Users/Michael Scopchanov/Desktop/untitled9/main.cpp"
"/Users/Michael Scopchanov/Desktop/untitled9/MainWindow.cpp"
"/Users/Michael Scopchanov/Desktop/untitled9/MyLabel.cpp"
This, show in the Output
and the text of m_textEdit is set to:
0->/Users/Michael Scopchanov/Desktop/untitled9/MyLabel.cpp<-/Users/Michael Scopchanov/Desktop/untitled9/
I'm trying to build a GUI app, and I'm doing this through Qt. I also want to create a multi window application: I want that when I hit a button the other window shows up ("hiding" the previous one). Is that a GDI?
So far, I have create a .ui file for every window I want (currently 4), and I'm trying to connect them that way (the main window, with the other 3).
How could I do that?
I'm sending the file of the program in order to make my problema more undestandable:
main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
StudyWindow s;
QStackedWidget *stackedWidget = new QStackedWidget;
stackedWidget->addWidget(w);
stackedWidget->addWidget(s);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(stackedWidget);
setLayout(layout);
w.show();
return a.exec();
}
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ConnectStuff();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::ConnectStuff()
{
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
#include <QLayout>
#include <QStackedWidget>
#include "study.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
void ConnectStuff();
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
study.h
#ifndef STUDYWINDOW_H
#define STUDYWINDOW_H
#include <QMainWindow>
#include <QPushButton>
namespace Ui {
class StudyWindow;
}
class StudyWindow : public QMainWindow
{
Q_OBJECT
public:
explicit StudyWindow(QWidget *parent = 0);
~StudyWindow();
private:
Ui::StudyWindow *ui;
};
#endif // STUDYWINDOW_H
ui_Study.h
/********************************************************************************
** Form generated from reading UI file 'Study.ui'
**
** Created: Tue 20. Mar 20:10:56 2012
** by: Qt User Interface Compiler version 4.7.4
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_STUDY_H
#define UI_STUDY_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QHeaderView>
#include <QtGui/QMainWindow>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QPushButton>
#include <QtGui/QStatusBar>
#include <QtGui/QTreeWidget>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_StudyWindow
{
public:
QAction *actionVoltar;
QAction *actionSair;
QWidget *centralwidget;
QTreeWidget *treeWidget;
QPushButton *pushButton;
QMenuBar *menubar;
QMenu *menuVoltar;
QStatusBar *statusbar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(800, 600);
actionVoltar = new QAction(MainWindow);
actionVoltar->setObjectName(QString::fromUtf8("actionVoltar"));
actionSair = new QAction(MainWindow);
actionSair->setObjectName(QString::fromUtf8("actionSair"));
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
treeWidget = new QTreeWidget(centralwidget);
QFont font;
font.setPointSize(8);
font.setBold(true);
font.setWeight(75);
QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem();
__qtreewidgetitem->setFont(0, font);
treeWidget->setHeaderItem(__qtreewidgetitem);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
treeWidget->setObjectName(QString::fromUtf8("treeWidget"));
treeWidget->setGeometry(QRect(0, 110, 161, 451));
pushButton = new QPushButton(centralwidget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(0, 0, 75, 23));
MainWindow->setCentralWidget(centralwidget);
menubar = new QMenuBar(MainWindow);
menubar->setObjectName(QString::fromUtf8("menubar"));
menubar->setGeometry(QRect(0, 0, 800, 21));
menuVoltar = new QMenu(menubar);
menuVoltar->setObjectName(QString::fromUtf8("menuVoltar"));
MainWindow->setMenuBar(menubar);
statusbar = new QStatusBar(MainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
menubar->addAction(menuVoltar->menuAction());
menuVoltar->addAction(actionVoltar);
menuVoltar->addSeparator();
menuVoltar->addAction(actionSair);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
actionVoltar->setText(QApplication::translate("MainWindow", "Voltar", 0, QApplication::UnicodeUTF8));
actionSair->setText(QApplication::translate("MainWindow", "Sair", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem = treeWidget->headerItem();
___qtreewidgetitem->setText(1, QApplication::translate("MainWindow", "Items", 0, QApplication::UnicodeUTF8));
___qtreewidgetitem->setText(0, QApplication::translate("MainWindow", "Mat\303\251ria", 0, QApplication::UnicodeUTF8));
const bool __sortingEnabled = treeWidget->isSortingEnabled();
treeWidget->setSortingEnabled(false);
QTreeWidgetItem *___qtreewidgetitem1 = treeWidget->topLevelItem(0);
___qtreewidgetitem1->setText(0, QApplication::translate("MainWindow", "Portugu\303\252s", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem2 = treeWidget->topLevelItem(1);
___qtreewidgetitem2->setText(0, QApplication::translate("MainWindow", "Reda\303\247\303\243o", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem3 = treeWidget->topLevelItem(2);
___qtreewidgetitem3->setText(0, QApplication::translate("MainWindow", "Matem\303\241tica", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem4 = treeWidget->topLevelItem(3);
___qtreewidgetitem4->setText(0, QApplication::translate("MainWindow", "Biologia", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem5 = treeWidget->topLevelItem(4);
___qtreewidgetitem5->setText(0, QApplication::translate("MainWindow", "F\303\255sica", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem6 = treeWidget->topLevelItem(5);
___qtreewidgetitem6->setText(0, QApplication::translate("MainWindow", "Qu\303\255mica", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem7 = treeWidget->topLevelItem(6);
___qtreewidgetitem7->setText(0, QApplication::translate("MainWindow", "Hist\303\263ria", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem8 = treeWidget->topLevelItem(7);
___qtreewidgetitem8->setText(0, QApplication::translate("MainWindow", "Geografia", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem9 = treeWidget->topLevelItem(8);
___qtreewidgetitem9->setText(0, QApplication::translate("MainWindow", "Ingl\303\252s", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem10 = treeWidget->topLevelItem(9);
___qtreewidgetitem10->setText(0, QApplication::translate("MainWindow", "Espanhol", 0, QApplication::UnicodeUTF8));
treeWidget->setSortingEnabled(__sortingEnabled);
pushButton->setText(QApplication::translate("MainWindow", "Cansei!", 0, QApplication::UnicodeUTF8));
menuVoltar->setTitle(QApplication::translate("MainWindow", "Arquivo", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class StudyWindow: public Ui_StudyWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_STUDY_H
ui_mainwindow.h
/********************************************************************************
** Form generated from reading UI file 'mainwindow.ui'
**
** Created: Tue 20. Mar 20:10:56 2012
** by: Qt User Interface Compiler version 4.7.4
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QGroupBox>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QMainWindow>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QPlainTextEdit>
#include <QtGui/QPushButton>
#include <QtGui/QStatusBar>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public slots:
public:
QAction *actionAjuda;
QAction *actionLista_de;
QAction *actionSair;
QWidget *centralwidget;
QPushButton *pshBStudy;
QPushButton *pshBSimulator;
QPushButton *pshBExamCalen;
QPushButton *pshBReadOfDay;
QLabel *labelTitle;
QPlainTextEdit *plainTextNews;
QLabel *labelNews;
QGroupBox *groupBox;
QLabel *labelCollege;
QLabel *labelCourse;
QLabel *labelMemSince;
QLabel *labelLoggedWith;
QLabel *labelBP;
QStatusBar *statusbar;
QMenuBar *menuBar;
QMenu *menuArquivo;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(800, 600);
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(MainWindow->sizePolicy().hasHeightForWidth());
MainWindow->setSizePolicy(sizePolicy);
actionAjuda = new QAction(MainWindow);
actionAjuda->setObjectName(QString::fromUtf8("actionAjuda"));
actionLista_de = new QAction(MainWindow);
actionLista_de->setObjectName(QString::fromUtf8("actionLista_de"));
actionSair = new QAction(MainWindow);
actionSair->setObjectName(QString::fromUtf8("actionSair"));
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
pshBStudy = new QPushButton(centralwidget);
pshBStudy->setObjectName(QString::fromUtf8("pshBStudy"));
pshBStudy->setGeometry(QRect(140, 120, 161, 81));
pshBStudy->setDefault(true);
pshBSimulator = new QPushButton(centralwidget);
pshBSimulator->setObjectName(QString::fromUtf8("pshBSimulator"));
pshBSimulator->setGeometry(QRect(530, 120, 161, 81));
pshBExamCalen = new QPushButton(centralwidget);
pshBExamCalen->setObjectName(QString::fromUtf8("pshBExamCalen"));
pshBExamCalen->setGeometry(QRect(140, 260, 161, 81));
pshBReadOfDay = new QPushButton(centralwidget);
pshBReadOfDay->setObjectName(QString::fromUtf8("pshBReadOfDay"));
pshBReadOfDay->setGeometry(QRect(530, 260, 161, 81));
labelTitle = new QLabel(centralwidget);
labelTitle->setObjectName(QString::fromUtf8("labelTitle"));
labelTitle->setGeometry(QRect(200, 10, 431, 71));
QFont font;
font.setPointSize(23);
labelTitle->setFont(font);
plainTextNews = new QPlainTextEdit(centralwidget);
plainTextNews->setObjectName(QString::fromUtf8("plainTextNews"));
plainTextNews->setGeometry(QRect(610, 440, 181, 111));
plainTextNews->setReadOnly(true);
labelNews = new QLabel(centralwidget);
labelNews->setObjectName(QString::fromUtf8("labelNews"));
labelNews->setGeometry(QRect(610, 420, 81, 16));
groupBox = new QGroupBox(centralwidget);
groupBox->setObjectName(QString::fromUtf8("groupBox"));
groupBox->setGeometry(QRect(0, 460, 431, 91));
labelCollege = new QLabel(groupBox);
labelCollege->setObjectName(QString::fromUtf8("labelCollege"));
labelCollege->setGeometry(QRect(230, 50, 111, 16));
labelCourse = new QLabel(groupBox);
labelCourse->setObjectName(QString::fromUtf8("labelCourse"));
labelCourse->setGeometry(QRect(230, 30, 111, 16));
labelMemSince = new QLabel(groupBox);
labelMemSince->setObjectName(QString::fromUtf8("labelMemSince"));
labelMemSince->setGeometry(QRect(10, 50, 111, 16));
labelLoggedWith = new QLabel(groupBox);
labelLoggedWith->setObjectName(QString::fromUtf8("labelLoggedWith"));
labelLoggedWith->setGeometry(QRect(10, 30, 111, 16));
labelBP = new QLabel(groupBox);
labelBP->setObjectName(QString::fromUtf8("labelBP"));
labelBP->setGeometry(QRect(10, 70, 111, 16));
MainWindow->setCentralWidget(centralwidget);
statusbar = new QStatusBar(MainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
menuBar = new QMenuBar(MainWindow);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 800, 21));
menuArquivo = new QMenu(menuBar);
menuArquivo->setObjectName(QString::fromUtf8("menuArquivo"));
MainWindow->setMenuBar(menuBar);
QWidget::setTabOrder(pshBStudy, pshBSimulator);
QWidget::setTabOrder(pshBSimulator, pshBExamCalen);
QWidget::setTabOrder(pshBExamCalen, pshBReadOfDay);
QWidget::setTabOrder(pshBReadOfDay, plainTextNews);
menuBar->addAction(menuArquivo->menuAction());
menuArquivo->addAction(actionSair);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
actionAjuda->setText(QApplication::translate("MainWindow", "Sobre...", 0, QApplication::UnicodeUTF8));
actionLista_de->setText(QApplication::translate("MainWindow", "Lista de Provas", 0, QApplication::UnicodeUTF8));
actionSair->setText(QApplication::translate("MainWindow", "Sair...", 0, QApplication::UnicodeUTF8));
pshBStudy->setText(QApplication::translate("MainWindow", "Estudar!", 0, QApplication::UnicodeUTF8));
pshBSimulator->setText(QApplication::translate("MainWindow", "Simulado", 0, QApplication::UnicodeUTF8));
pshBExamCalen->setText(QApplication::translate("MainWindow", "Calend\303\241rio de Provas", 0, QApplication::UnicodeUTF8));
pshBReadOfDay->setText(QApplication::translate("MainWindow", "Leitura do Dia", 0, QApplication::UnicodeUTF8));
labelTitle->setText(QApplication::translate("MainWindow", "Escolha o que quer fazer hoje: ", 0, QApplication::UnicodeUTF8));
labelNews->setText(QApplication::translate("MainWindow", "Novidades:", 0, QApplication::UnicodeUTF8));
groupBox->setTitle(QApplication::translate("MainWindow", "Informa\303\247\303\265es", 0, QApplication::UnicodeUTF8));
labelCollege->setText(QApplication::translate("MainWindow", "Faculdade:", 0, QApplication::UnicodeUTF8));
labelCourse->setText(QApplication::translate("MainWindow", "Curso Pretendido:", 0, QApplication::UnicodeUTF8));
labelMemSince->setText(QApplication::translate("MainWindow", "Membro desde:", 0, QApplication::UnicodeUTF8));
labelLoggedWith->setText(QApplication::translate("MainWindow", "Voc\303\252 esta logado com: ", 0, QApplication::UnicodeUTF8));
labelBP->setText(QApplication::translate("MainWindow", "BP: ", 0, QApplication::UnicodeUTF8));
menuArquivo->setTitle(QApplication::translate("MainWindow", "Arquivo", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H
You can use the signal and slot mechanism, for that please go through the following documentation..
http://qt-project.org/doc/qt-4.8/signalsandslots.html
Now you can connect the signal of one window to the another and in the slot of the other window you show the other window and hide the previous one.
well, after some patience and study of the Qt Architecture I did it.
I just added that line in Ui_MainWindow::SetupUI(blablabla)
studyWindow = new StudyWindow(MainWindow);
QObject::connect(pshBStudy, SIGNAL(clicked()), studyWindow, SLOT(show()));
And the respective attribute to Ui_MainWindow Class. And now it's working alright.
So you have one window A which "controls" the others W1, W2, ...., Wn?
One way is to do :
Associate each of the 3 buttons Bi to their respective window Wi (like a map where a key is a button and the value the QMainWindow)
Create a custom slot in window A and connect the clicked() signals of each of the buttons to this slot.
In this slot you find which button Bi sent the signal using sender(). You find the associated window Wi and you call show(). In the meanwhile you call hide() for all other windows Wj, j!=i
All the methods cited above are either in the doc of QWidget or Qobject, so you should read it.
I have made a user interface in Qt Designer and i now want to display the data.I want to make use of the multiple inheritance approach.Here is the code for the user interface.
/********************************************************************************
** Form generated from reading UI file 'prototypejI3444.ui'
**
** Created: Mon May 30 10:04:01 2011
** by: Qt User Interface Compiler version 4.7.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef PROTOTYPEJI3444_H
#define PROTOTYPEJI3444_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QGridLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QMainWindow>
#include <QtGui/QMenuBar>
#include <QtGui/QPushButton>
#include <QtGui/QStatusBar>
#include <QtGui/QTableView>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *centralwidget;
QGridLayout *gridLayout;
QVBoxLayout *verticalLayout_2;
QLabel *label;
QVBoxLayout *verticalLayout_3;
QLineEdit *lineEdit;
QVBoxLayout *verticalLayout_4;
QLabel *label_2;
QVBoxLayout *verticalLayout_5;
QLineEdit *lineEdit_2;
QVBoxLayout *verticalLayout_6;
QLabel *label_3;
QVBoxLayout *verticalLayout_7;
QLineEdit *lineEdit_3;
QTableView *tableView;
QPushButton *pushButton_2;
QPushButton *pushButton_3;
QPushButton *pushButton_4;
QPushButton *pushButton_5;
QPushButton *pushButton_6;
QPushButton *pushButton;
QMenuBar *menubar;
QStatusBar *statusbar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(800, 600);
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
gridLayout = new QGridLayout(centralwidget);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
verticalLayout_2 = new QVBoxLayout();
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
label = new QLabel(centralwidget);
label->setObjectName(QString::fromUtf8("label"));
verticalLayout_2->addWidget(label);
gridLayout->addLayout(verticalLayout_2, 1, 0, 1, 1);
verticalLayout_3 = new QVBoxLayout();
verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
lineEdit = new QLineEdit(centralwidget);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
verticalLayout_3->addWidget(lineEdit);
gridLayout->addLayout(verticalLayout_3, 1, 1, 1, 1);
verticalLayout_4 = new QVBoxLayout();
verticalLayout_4->setObjectName(QString::fromUtf8("verticalLayout_4"));
label_2 = new QLabel(centralwidget);
label_2->setObjectName(QString::fromUtf8("label_2"));
verticalLayout_4->addWidget(label_2);
gridLayout->addLayout(verticalLayout_4, 2, 0, 1, 1);
verticalLayout_5 = new QVBoxLayout();
verticalLayout_5->setObjectName(QString::fromUtf8("verticalLayout_5"));
lineEdit_2 = new QLineEdit(centralwidget);
lineEdit_2->setObjectName(QString::fromUtf8("lineEdit_2"));
verticalLayout_5->addWidget(lineEdit_2);
gridLayout->addLayout(verticalLayout_5, 2, 1, 1, 1);
verticalLayout_6 = new QVBoxLayout();
verticalLayout_6->setObjectName(QString::fromUtf8("verticalLayout_6"));
label_3 = new QLabel(centralwidget);
label_3->setObjectName(QString::fromUtf8("label_3"));
verticalLayout_6->addWidget(label_3);
gridLayout->addLayout(verticalLayout_6, 3, 0, 1, 1);
verticalLayout_7 = new QVBoxLayout();
verticalLayout_7->setObjectName(QString::fromUtf8("verticalLayout_7"));
lineEdit_3 = new QLineEdit(centralwidget);
lineEdit_3->setObjectName(QString::fromUtf8("lineEdit_3"));
verticalLayout_7->addWidget(lineEdit_3);
gridLayout->addLayout(verticalLayout_7, 3, 1, 1, 1);
tableView = new QTableView(centralwidget);
tableView->setObjectName(QString::fromUtf8("tableView"));
gridLayout->addWidget(tableView, 0, 0, 1, 2);
pushButton_2 = new QPushButton(centralwidget);
pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
gridLayout->addWidget(pushButton_2, 2, 2, 1, 1);
pushButton_3 = new QPushButton(centralwidget);
pushButton_3->setObjectName(QString::fromUtf8("pushButton_3"));
gridLayout->addWidget(pushButton_3, 3, 2, 1, 1);
pushButton_4 = new QPushButton(centralwidget);
pushButton_4->setObjectName(QString::fromUtf8("pushButton_4"));
gridLayout->addWidget(pushButton_4, 1, 3, 1, 1);
pushButton_5 = new QPushButton(centralwidget);
pushButton_5->setObjectName(QString::fromUtf8("pushButton_5"));
gridLayout->addWidget(pushButton_5, 2, 3, 1, 1);
pushButton_6 = new QPushButton(centralwidget);
pushButton_6->setObjectName(QString::fromUtf8("pushButton_6"));
gridLayout->addWidget(pushButton_6, 3, 3, 1, 1);
pushButton = new QPushButton(centralwidget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
gridLayout->addWidget(pushButton, 1, 2, 1, 1);
MainWindow->setCentralWidget(centralwidget);
tableView->raise();
pushButton_2->raise();
pushButton_3->raise();
pushButton_4->raise();
pushButton_5->raise();
pushButton_6->raise();
pushButton->raise();
menubar = new QMenuBar(MainWindow);
menubar->setObjectName(QString::fromUtf8("menubar"));
menubar->setGeometry(QRect(0, 0, 800, 18));
MainWindow->setMenuBar(menubar);
statusbar = new QStatusBar(MainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("MainWindow", "FirstName:", 0, QApplication::UnicodeUTF8));
label_2->setText(QApplication::translate("MainWindow", "SecondName:", 0, QApplication::UnicodeUTF8));
label_3->setText(QApplication::translate("MainWindow", "City:", 0, QApplication::UnicodeUTF8));
pushButton_2->setText(QApplication::translate("MainWindow", "New", 0, QApplication::UnicodeUTF8));
pushButton_3->setText(QApplication::translate("MainWindow", "Delete", 0, QApplication::UnicodeUTF8));
pushButton_4->setText(QApplication::translate("MainWindow", "Next", 0, QApplication::UnicodeUTF8));
pushButton_5->setText(QApplication::translate("MainWindow", "Previous", 0, QApplication::UnicodeUTF8));
pushButton_6->setText(QApplication::translate("MainWindow", "First", 0, QApplication::UnicodeUTF8));
pushButton->setText(QApplication::translate("MainWindow", "Save", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // PROTOTYPEJI3444_H
In the multiple inheritance method there is a .h file and its corresponding .cpp.I want someone to guide me on where to make a connection to sqlite database(whether its in the .cpp file or the .h file) and how to communicate with the UI file i have shown to show data from the database on Qtableview.
Thanks.
You instantiate QSqlTableModel, associate it the the view using setModel, and initialize the appropriate table properties to the model. Do all of it in init.