In a user setting page, in that window i want a combobox that once you have selected something it will change the text of a line edit. for example
someone chose patrick and than the text change to his address and phone number.
im suspecting the code will look something like this:
if Qcombobox == "patrick"{
QlineEdit_phone = "911"
}
i have started to use QT designer and im lost on how Iam connecting slot and signal with object also.
the slot to change the editline by the change of selection through a combobox look like:
void pagesetting::on_comboBox_activated(const QString &arg1)
{
if (arg1=="gmail"){
ui-> lineEdit_port -> setText("465");
ui -> lineEdit_host -> setText("smtp.gmail.com");
}
if (arg1=="yahoo"){
ui-> lineEdit_port -> setText("465");
ui -> lineEdit_host -> setText("smtp.mail.yahoo.com");
}
}
if you use qt designer you still need to delcare everything if you want to play with the object
I created a menu in my QMainWindow derived class, and added a QWidget to it via QWidgetAction. Now my app does not close and stays in infinite loop when I try to close it. Any hints on why this happens?
Here's the code:
MainWindow* parent = ...;
auto menu = parent->menuBar()->addMenu("Menu");
auto action = new QWidgetAction(menu);
auto widget = new QLabel("Lol");
action->setDefaultWidget(widget);
menu->addAction(action);
This happens under OSX Sierra, Qt 5.7
I am trying to learn QT and wanted to set the text of a lineEdit when pressing a push button. I tried using this code
void Notepad::on_pushButton_10_clicked(){
Notepad::lineEdit -> setText("test");
}
but it does not work since lineEdit is not a member of Notepad. How do I reference lineEdit?
Your code will look something like below :
void Notepad::on_pushButton_10_clicked(){
ui->lineEdit->setText("test");
}
provided that you named the lineEdit Widget as the lineEdit.
For some reason all my menu bar items are greyed out when I use the native menu bar on OS X Mavericks:
I create the menu actions using the following code:
newAct = new QAction(tr("&New"), this);
newAct->setShortcuts(QKeySequence::New);
newAct->setStatusTip(tr("New"));
newAct->setShortcutContext(Qt::ApplicationShortcut);
newAct->setEnabled(true);
newAct->setAutoRepeat(false);
addAction(newAct);
connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
...
These actions are then added to the menubar like this:
// _menuBar = new QMenuBar(0);
_menuBar = menuBar();
//_menuBar->setNativeMenuBar(false);
fileMenu = _menuBar->addMenu(tr("&File"));
fileMenu->addAction(newAct);
Uncommenting the first line shows the same behaviour. It does however work fine when I use the the non-native menu bar.
Qt version:
$ /usr/local/qt/5.3/clang_64/bin/qmake -v
QMake version 3.0
Using Qt version 5.3.1 in /usr/local/qt/5.3/clang_64/lib
Any ideas/suggestions?
I suspect this line is your culprit:
addAction(newAct);
You shouldn't be adding the QActions to your window, since you'll be adding them to the fileMenu object instead. Try removing the above line.
I had the same problem.
Setting the windowModality property of my MainWindow to NonModal worked for me.
I’m trying to bind Qt::META + Qt::Key_Tab shortcut in QTabWidget to switch tabs (like it works in chrome or many other applications).
I have tried every single solution found in google, but this shortcut combination is not working.
I have tried:
Combinations like Qt::Key_Control + Qt::Key_Tab, Qt::Key_Meta + Qt::Key_Tab, QKeySequence(Qt::Key_Meta, Qt::Key_Tab), QKeySequence(Qt::META, Qt::Key_Tab) etc.
QShortcut
QAction
capturing keys using virtual QWidget::event
capturing keys using virtual QWidget::eventFilter with installEventFilter
all relative like keyPressed and etc..
QWidget::event/QWidget::eventFilter catches Shift+Tab, Alt+Tab, but not Ctrl(META)+Tab. When I press Ctrl I see my qDebug output, when I press Ctrl + Tab nothing happens.
Can somebody explain me what is wrong and so special with this particular key combination in QT on OSX?
Doesn't matter what widget, I have created clean GUI project with no other widgets in it - still the same.
Some information:
OSX Mountain Lion 10.8.5
QT 5.2
BTW, In Qt Creator I’m not able to set Ctrl+Tab shortcut either, thats really ridiculous.
Note: It works great on Windows, it doesn't work on OSX!
I appreciate any help.
Simple code with QAction:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QAction *pAction = new QAction(this);
QKeySequence keySequence = Qt::META + Qt::Key_Tab; // Not working
// or
QKeySequence keySequence = Qt::ALT + Qt::Key_Tab; // Works Alt+Tab
// or
QKeySequence keySequence = QKeySequence(Qt::Key_Meta, Qt::Key_Tab); // Not working
// or
QKeySequence keySequence = QKeySequence(Qt::META, Qt::Key_Tab); // Not working
pAction->setShortcut(keySequence);
connect(pAction, SIGNAL(triggered()), this, SLOT(shortcut_NextTab()));
addAction(pAction);
}
And slot function:
void MainWindow::shortcut_NextTab()
{
qDebug() << "LOL";
}
Expecting to see LOL in Application output, when pressing Ctrl+Tab.
This seems to be a bug in Qt on Cocoa. See QTBUG-8596 and QTBUG-12232. The first bug report has a comment that says that it works if you add the QAction to the menu. I was experiencing the same problem as you, and that solution worked for me.
In this line:
QKeySequence keySequence = Qt::Key_Meta + Qt::Key_Tab;
You are just adding integers. Per QT documentation:
QKeySequence::QKeySequence ( int k1, int k2 = 0, int k3 = 0, int k4 = 0 )
Constructs a key sequence with up to 4 keys k1, k2, k3 and k4.
The key codes are listed in Qt::Key and can be combined with modifiers (see Qt::Modifier) such as Qt::SHIFT, Qt::CTRL, Qt::ALT, or Qt::META.
Meaning:
if you want a sequence, you need to use two-argument constructor to QKeySequence, not just add two integers together (which is what you are doing) and use one-argument constructor.
If you want a modifier - which I assume means holding a key down - use QT::Modifier, not Qt::Key_*.