Hi
I have QCombox without items. After clicking on the combobox I would like to showmessage but I cannot find slot "Clicked" or something similar.
How to do it ?
Regards
Artur
Hi
I have QCombox without items. After clicking on the combobox I would like to showmessage but I cannot find slot "Clicked" or something similar.
How to do it ?
Regards
Artur
There is no such signal. If you want to have one, subclass, reimplement mouse events and emit such signal yourself.
... in short, add a pushButton, eish, that is just mean - lol.
No. Do as Wysota has said. The mouse event will hook clicking the combo box and emit a "clicked" signal - perhaps only sometimes (when the combo box is empty). If the combo box isn't empty, you get a signal from the clicked item.
If it is not problem please give me an example.
Thank you for help
How to do it using QMouseEvent.
How to determine that the left button of mouse was clicked on the Combobox.
Qt Code:
if(e->button() == Qt::LeftMouseButton) emit clicked(); }To copy to clipboard, switch view to plain text mode
My Code
Qt Code:
{ if (event->button()==Qt::LeftButton) emit clicked(); }To copy to clipboard, switch view to plain text mode
Should I create clicked signal ? because Now I have the following error: 'clicked' was not declared in this scope
but It is still not clear for me. The signal will be sent each time when the left button of mouse is clicked even if the pointer of mouse there is out of Combobox area.
Second question:
Is it possible to check using a method if a slot was called by signal or was called another method
for example:
I have a slot
Qt Code:
void Test:: test1 (void) { qDebug () << "TEST"; }To copy to clipboard, switch view to plain text mode
I can call it using the following code:
test();
or it can be called by signal.
I would like to know which method was used to call the slot.
No. A widget receives mouse events only when they happen over its area.
QObject::sender()Is it possible to check using a method if a slot was called by signal or was called another method
What for?I would like to know which method was used to call the slot.
As I thought It did not worksomething is wrong
My code:
Qt Code:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QMouseEvent> #include <QDebug> ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } { if (event->button()==Qt::LeftButton) emit clicked(); } void MainWindow::test (void){ qDebug () << "TEST SIGNAL"; }To copy to clipboard, switch view to plain text mode
Qt Code:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> namespace Ui { class MainWindow; } { Q_OBJECT public: ~MainWindow(); void test (void); signals: void clicked(void); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_HTo copy to clipboard, switch view to plain text mode
I have a method open_file and in the first case I choose proper file from C: disk (QfileDialog) in second case the same file is downloaded from server and write for example on C: disk.
In second case I know file path so I do not know to choose file once again but used path which was chosen before writing file.
How to skip the part of code which open Qfiledialog.
Regards
Artur
First of all this is a handler for mouseMoveEvent for which button() always returns 0 (obviously a move is not caused by a button). Second of all this is an event handler for MainWindow and not the combobox.
Why don't you store the path in some variable and if the variable is not empty you will know you already have the path?I have a method open_file and in the first case I choose proper file from C: disk (QfileDialog) in second case the same file is downloaded from server and write for example on C: disk.
In second case I know file path so I do not know to choose file once again but used path which was chosen before writing file.
How to skip the part of code which open Qfiledialog.
I made a mistake. I do not know Why I used Mosemove...
Qt Code:
{ if (event->button()==Qt::LeftButton) emit clicked(); }To copy to clipboard, switch view to plain text mode
but know I have the error: 'clicked' was not declared in this scope
something is wrog I am a bit confused
I created the following code:
Qt Code:
#include "mycombobox.h" { } MyCombobox::~MyCombobox() { } { if (event->button()==Qt::LeftButton) emit clicked(); }To copy to clipboard, switch view to plain text mode
Qt Code:
#ifndef MYCOMBOBOX_H #define MYCOMBOBOX_H #include <QObject> #include <QWidget> #include <QComboBox> #include <QMouseEvent> { Q_OBJECT public: ~MyCombobox(); protected: signals: void clicked(void); }; #endif // MYCOMBOBOX_HTo copy to clipboard, switch view to plain text mode
but something is wrong I have the following errors: undefined reference to `vtable for MyCombobox' and I do not know what is wrong
Thank you for your patience![]()
Last edited by arturs; 29th May 2015 at 17:39.
I edited my previous post because I sent it by my mistake
I do not know what is wrong, either. IMO, the code should work. Try:
(1) Remove QObject and QWidget includes - they are included by QComboBox
(2) Add "virtual" specifiers to the dtor and the mouse handler. Well, you need not according to the C++ specification - because both methods are already virtual.
(3) Remove the "void" parameter from clicked(). Well, the "old" syntax is still legal but contemporary C++ is rather "clicked()" than "clicked(void)"
(3) If it does not help, delete the compiled files directory and make Creator to build everything from (real) scratch.
Bookmarks