SOLVED: URGENT!! Help with QT
-
Hi, i have searched a lot and couldn't find (well, i did but none helped) relevant clues to my questions. There are 7 questions i need help with:
- How do you set up a line edit to be uppercase?
- How do you set up hints (the comments that appear, once hovering your mouse over function, to help user understand what is required of them)?
- Can you change the colour of a checkbox? Inside the box, that is. If so, how?
- How can you change the colour of a button (and text displayed on the button) when it is pressed and again when it is released?
- Is it possible to change the background of a form to an image? If so, how?
- How can you enable the enter key on your keyboard to function whilst you are running your form (e.g. in my case, if i tab to have the button selected, i cannot enter (keyboard) for it to click, i have to use my mouse)?
- How can you compare the entered text in line edit to a specific text you mentioned in the program?
-
Here's my program, if it might help:
@
#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);ui->textbox1->setMaxLength(50); ui->textbox2->setMaxLength(65); ui->textbox3->setMaxLength(40); ui->textbox4->setMaxLength(3); ui->textbox4->setValidator(new QIntValidator(0,999, this));
}
MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_button1_clicked()
{
QString UART;
QString scanned;
UART = "Universal Asynchronous Receiver/Transmitter";ui->textbox1->clear(); ui->textbox1->insert(UART); ui->textbox1->setDisabled(true); ui->checkbox1->setChecked(true); ui->button1->setDisabled(true);
}
void MainWindow::on_button2_clicked()
{
QString USART;
USART = "Universal Synchronous-Asynchronous Receiver/Transmitter";ui->textbox2->clear(); ui->textbox2->insert(USART); ui->textbox2->setDisabled(true); ui->checkbox2->setChecked(true); ui->button2->setDisabled(true);
}
void MainWindow::on_button3_clicked()
{
QString LIN;
LIN = "Local Interconnected Network";ui->textbox3->clear(); ui->textbox3->insert(LIN); ui->textbox3->setDisabled(true); ui->checkbox3->setChecked(true); ui->button3->setDisabled(true);
}
void MainWindow::on_button4_clicked()
{
QString slaves;
slaves = "16";ui->textbox4->clear(); ui->textbox4->insert(slaves); ui->textbox4->setDisabled(true); ui->checkbox4->setChecked(true); ui->button4->setDisabled(true);
}
void MainWindow::on_clearbutton_clicked()
{
ui->textbox1->clear();
ui->textbox1->setEnabled(true);
ui->checkbox1->setChecked(false);
ui->button1->setEnabled(true);ui->textbox2->clear(); ui->textbox2->setEnabled(true); ui->checkbox2->setChecked(false); ui->button2->setEnabled(true); ui->textbox3->clear(); ui->textbox3->setEnabled(true); ui->checkbox3->setChecked(false); ui->button3->setEnabled(true); ui->textbox4->clear(); ui->textbox4->setEnabled(true); ui->checkbox4->setChecked(false); ui->button4->setEnabled(true);
}
void MainWindow::on_closebutton_clicked()
{
close();
}
@ -
The answers are in the Qt Documentation, but probably you are new to Qt and you don't know where to search.
Here some hints on where to look for in the documentation:-
How do you set up a line edit to be uppercase?
QWidget has a metod called inputMethodHints where you can set up that you prefer uppercase only. Or, if it does not works you can use a QValidator to force uppercase. Or, you can connect a slot to textChanged slot and force uppercase -
How do you set up hints (the comments that appear, once hovering your mouse over function, to help user understand what is required of them)?
QToolTip -
Can you change the colour of a checkbox? Inside the box, that is. If so, how?
You can use the Qt Style Sheet for customize the appearance of QWidgets -
How can you change the colour of a button (and text displayed on the button) when it is pressed and again when it is released?
With a Qt Style Sheet and/or using two slots connected to the pressed and release signals -
Is it possible to change the background of a form to an image? If so, how?
Again, try with Qt Style Sheet. Otherwise, you can lay behind the form a QLabel with a QPixmap setted. The QWidgets are generally transparent, so the image will appear as a form background -
How can you enable the enter key on your keyboard to function whilst you are running your form (e.g. in my case, if i tab to have the button selected, i cannot enter (keyboard) for it to click, i have to use my mouse)?
Not sure how to solve it. -
How can you compare the entered text in line edit to a specific text you mentioned in the program?
Create a slot and connect it to the signal editingFinished (or another appropriate).
-
-
Lol ye i am new on QT and trying to get used to it.
Progress on questions:
-
I have tried the IMH you mentioned and played around with it a bit, didn't quite work, unless you know a code that'll work for it. Mine was somewhere around:
@
ui->textbox1->setInputMethodHints(Qt::ImhUppercaseOnly);
@
I have also tried the QValidator. If you can perhaps provide me with an example code then that'll be amazing. -
Thank you for that, problem is solved using toolkit.
-
The certain area i wanted to fill with colour wouldn't , so i'm classing it as not programmable.
-
I have tried that as well but couldn't figure out the format to program change the button colour and button text.
-
As for the background, i have no resource root apparently :/
-
Enabling the enter button, could not do, so leaving it at that.
-
Here is what i tried, again i also played around with it:
@
void MainWindow::on_button3_clicked()
{
QString LIN;
LIN = "Local Interconnected Network";
QString = scanned;
scanned = ui->textbox3->editingFinished();
if (ui->textbox3->text()==LIN)
{
ui->textbox3->clear();
ui->textbox3->insert(LIN);
ui->textbox3->setDisabled(true);
ui->checkbox3->setChecked(true);
ui->button3->setDisabled(true);
}
else
{
ui->textbox3->clear();
ui->textbox3->insert(LIN);
ui->textbox3->setDisabled(true);
ui->checkbox3->setChecked(false);
ui->button3->setDisabled(true);
}
}@
-
-
For the UI customization with Style sheets look at this example:
http://qt-project.org/doc/qt-4.8/widgets-stylesheet.htmlIn the example, the form background is customized, the check (and radio) buttons are completely customs and also the buttons.
For the other points, I suggest you to open one thread for each of the remaining with a title more expressive and without "URGENT", so other people can help you.
For example: open a new topic with the title: "Forcing uppercase only into QLineEdit". -
Ok, i shall do that. Thank you for your help!