All of these demos will be preset for the raspberry 'RPI3
but can easily be changed for x86_64 changing and uncommenting one line of code
I also tried this on Manjaro archlinux RPI3
'RPI3
PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -I/usr/include/arm-linux-gnueabihf/qt5 -fPIC
but lets say you want to test on an x86_64
well just comment out the the PRAGMA line for the RPI3
and uncomment the x86_64 PRAGMA line
'x86_64
PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -Wno-deprecated -fPIC -I/usr/include/x86_64-linux-gnu/qt5
I like archlinux Manjaro too very cutting edge software versions!
'Manjaro archlinux RPI
PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -I/usr/include/qt5 -fPIC
dowload the source code
PRAGMA INCLUDE <QtWidgets/QApplication> <QtWidgets/QMainWindow> <QtWidgets/QComboBox> <QtWidgets/QHBoxLayout> <QtWidgets/QLabel>
PRAGMA INCLUDE <QtWidgets/QPushButton> <QtWidgets/QStatusBar> <QtWidgets/QFrame> <QtWidgets/QVBoxLayout>
PRAGMA INCLUDE <QtWidgets/QListWidget> <QtCore/QDebug> <QtWidgets/QInputDialog>
PRAGMA INCLUDE <iostream>
PRAGMA LDFLAGS -lQt5Widgets -lQt5Gui -lQt5Core -lpthread -latomic
PRAGMA COMPILER g++
'RPI3
PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -I/usr/include/arm-linux-gnueabihf/qt5 -fPIC
'x86_64
'PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -Wno-deprecated -fPIC -I/usr/include/x86_64-linux-gnu/qt5
'Manjaro archlinux RPI
'PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -I/usr/include/qt5 -fPIC
OPTION PARSE FALSE
DECLARE app TYPE QApplication*
DECLARE hbox TYPE QHBoxLayout*
DECLARE vbox TYPE QVBoxLayout*
DECLARE add TYPE QPushButton*
DECLARE renamed TYPE QPushButton*
DECLARE removeme TYPE QPushButton*
DECLARE removeall TYPE QPushButton*
DECLARE lw TYPE QListWidget*
DECLARE Statusbar TYPE QStatusBar*
DECLARE w TYPE QWidget*
DECLARE inputDialog TYPE QInputDialog*
'---must include this <QtCore/QDebug>
'--- a new macro without formatting or casting or c++
DEF FN PRINTOUT(x) = qDebug() << (x)
'--------------------------------------
SUB addPressed()
'--------------------------------------
LOCAL c_text TYPE QString
LOCAL s_text TYPE QString
LOCAL r TYPE int
Statusbar->showMessage( "add", 4000)
'---note the 4000 is 4 seconds to view the message
'--- place holder
b$ = "some string here"
'--- when you need a string or value as a result QInputDialog:: works (this wont inputDialog->)
c_text = QInputDialog::getText(0, "Input dialog","add something here:", QLineEdit::Normal,b$)
s_text = c_text.simplified()
IF s_text.isEmpty() == false THEN
lw->addItem(c_text)
r = lw->count() - 1
lw->setCurrentRow(r)
END IF
END SUB
'--------------------------------------
SUB renamePressed()
'--------------------------------------
Statusbar->showMessage("rename ", 4000)
LOCAL curitem TYPE QListWidgetItem*
LOCAL r TYPE int
LOCAL r_text TYPE QString
LOCAL c_text TYPE QString
LOCAL s_text TYPE QString
LOCAL removeitem TYPE QListWidgetItem*
curitem = lw->currentItem()
r = lw->row(curitem)
c_text = curitem->text()
'---special note replace "this" with 0 or else your cast will not work
r_text = QInputDialog::getText(0,"Item", "Enter new item", QLineEdit::Normal, c_text)
s_text = r_text.simplified()
IF s_text.isEmpty() == false THEN
removeitem = lw->takeItem(r)
delete removeitem
lw->insertItem(r, s_text)
lw->setCurrentRow(r)
END IF
END SUB
'--------------------------------------
SUB removePressed()
'--------------------------------------
Statusbar->showMessage("remove", 4000)
LOCAL r TYPE int
LOCAL removeitem TYPE QListWidgetItem*
r = lw->currentRow()
IF (r != -1) THEN
removeitem = lw->takeItem(r)
delete removeitem
END IF
END SUB
'--------------------------------------
SUB removeallPressed()
'--------------------------------------
Statusbar->showMessage("remove all ", 4000)
IF (lw->count() != 0) THEN
lw->clear()
END IF
END SUB
'--------------------------------------
SUB clickedsub()
'--------------------------------------
'--- I figured out how to get the selected from a click
Statusbar->showMessage(lw->currentItem()->text(), 4000)
'--- how to get the terminal out strings of the selected text
PRINTOUT(lw->currentItem()->text())
END SUB
app = new QApplication(argc, argv)
'--- Create a widget instead of a window
w = new QWidget()
hbox = new QHBoxLayout()
vbox = new QVBoxLayout()
lw = new QListWidget()
lw->addItem("apples")
lw->addItem("oranges")
lw->addItem("mangos")
lw->addItem("bananas")
lw->addItem("lemons")
add = new QPushButton("Add")
renamed = new QPushButton("Rename")
removeme = new QPushButton("Remove")
removeall = new QPushButton("Remove All")
vbox->setSpacing(3)
vbox->addStretch(1)
vbox->addWidget(add)
vbox->addWidget(renamed)
vbox->addWidget(removeme)
vbox->addWidget(removeall)
vbox->addStretch(1)
hbox->addWidget(lw)
hbox->addSpacing(15)
hbox->addLayout(vbox)
'---will pop up as its own widget
inputDialog = new QInputDialog()
'--only the next line goes in the callback or it wont work
'inputDialog->getText(0, "Input dialog","add something here:", QLineEdit::Normal,"hello")
inputDialog->setOkButtonText("OK")
inputDialog->setCancelButtonText("Cancel")
inputDialog->setTextEchoMode(QLineEdit::Normal)
'--- Set the hbox as the layout of the widget
'--- this fixes having a window and a widget that are not joined
Statusbar = new QStatusBar()
'---add the statusbar widget
hbox->addWidget(Statusbar, 3, Qt::AlignBottom)
w->setLayout(hbox )
QObject::connect(add, &QPushButton::clicked, addPressed)
QObject::connect(renamed, &QPushButton::clicked, renamePressed)
QObject::connect(removeme, &QPushButton::clicked, removePressed)
QObject::connect(removeall, &QPushButton::clicked, removeallPressed)
'--- added a custom callback to get the listwidget
QObject::connect(lw, &QListWidget::itemClicked, clickedsub)
w->resize(500, 200)
w->setWindowTitle("Listwidget demo advanced")
inputDialog->hide()
w->show()
return app->exec()