Page 2 of 2 FirstFirst 12
Results 21 to 32 of 32

Thread: Qcombobox

  1. #21

    Default Re: Qcombobox

    Qt Code:
    1. #include "mycombobox.h"
    2.  
    3. MyCombobox::MyCombobox(QWidget *parent) : QComboBox(parent)
    4. {
    5.  
    6. }
    7.  
    8. MyCombobox::~MyCombobox()
    9. {
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #ifndef MYCOMBOBOX_H
    2. #define MYCOMBOBOX_H
    3.  
    4. #include <QObject>
    5. #include <QWidget>
    6. #include <QComboBox>
    7.  
    8. class MyCombobox : public QComboBox
    9. {
    10. Q_OBJECT
    11. public:
    12. MyCombobox(QWidget *parent = 0);
    13. ~MyCombobox();
    14. };
    15.  
    16. #endif // MYCOMBOBOX_H
    To copy to clipboard, switch view to plain text mode 

    The error is when I only use the above code without QMouseEvent etc

  2. #22
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: Qcombobox

    Code looks ok. Be sure to include 'mycombobox.h' in the HEADERS list in .pro file and re-run qmake.
    Can you verify that "moc_mycombobox.cpp" file is created somewhere under the build directory ?

  3. #23

    Default Re: Qcombobox

    It was not moc_mycom....

    I deleted all files from catalogue where are files moc* etc and rebuild project once again. Now Everything is ok.

    Thank you for help


    Added after 20 minutes:


    Ok. It works after clicking is emited signal ... but I lost rest of action of QCombobox Only cliking works.
    Last edited by arturs; 29th May 2015 at 20:18.

  4. #24
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Qcombobox

    Quote Originally Posted by arturs View Post
    Ok. It works after clicking is emited signal ... but I lost rest of action of QCombobox Only cliking works.
    Because you are not calling the base-class implementation of the event handler.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #25

    Default Re: Qcombobox

    What Should I change in my code ?

  6. #26
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: Qcombobox

    Call the base-class implementation of the event handler No Qt magic here, just the standard C++ way to call the base-class implementation of virtual method in derived class.

  7. #27

    Default Re: Qcombobox

    My present code:
    Qt Code:
    1. void MyComboBox::mousePressEvent(QMouseEvent *event)
    2. {
    3.  
    4.  
    5.  
    6. if (event->button()==Qt::LeftButton) emit clicked();
    7.  
    8. else {
    9.  
    10. QComboBox::mousePressEvent(event);
    11.  
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    In standard QCombobox implementation leftbutton of mouse expands a list, but now after clicking mouse is emited signal (it is clear) so I cannot expand the list.
    something I do not understand but I do not know what. Where to call base -class.

    My application is:

    I have a qCombobox and there is list of available com ports. If a port is uninstalled or new installed I would like to refresh my com ports list automatically.

    Maybe is better way to do it.

    Regards
    Artur
    Last edited by arturs; 31st May 2015 at 11:37.

  8. #28
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Qcombobox

    Quote Originally Posted by arturs View Post
    In standard QCombobox implementation leftbutton of mouse expands a list, but now after clicking mouse is emited signal (it is clear) so I cannot expand the list.
    something I do not understand but I do not know what. Where to call base -class.
    You need to develop some logic around your code. Your current code says "if left mouse button is clicked on the combobox, emit a clicked() signal, otherwise (not left mouse button is clicked) do whatever a regular combobox does". Your code doesn't say anything about the combo being empty or anything like that. The compiler does not browse the Internet while compiling your code and it will not encounter this thread and thus it will not know what you meant your code to do. You need to explicitly tell it what you want it to do by writing C++ code that implements the algorithm that solves your problem.

    I have a qCombobox and there is list of available com ports. If a port is uninstalled or new installed I would like to refresh my com ports list automatically.

    Maybe is better way to do it.
    Surely there is Rebuild the list whenever you detect a set of available ports is modified.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #29
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Qcombobox

    Rerun qmake after adding/removing the Q_OBJECT macro, then rebuild.

    Err... Ignore me, I missed a whole set of replies.
    Last edited by ChrisW67; 31st May 2015 at 21:28. Reason: updated contents

  10. #30

    Default Re: Qcombobox

    Quote Originally Posted by wysota View Post
    You need to develop some logic around your code. Your current code says "if left mouse button is clicked on the combobox, emit a clicked() signal, otherwise (not left mouse button is clicked) do whatever a regular combobox does". Your code doesn't say anything about the combo being empty or anything like that. The compiler does not browse the Internet while compiling your code and it will not encounter this thread and thus it will not know what you meant your code to do. You need to explicitly tell it what you want it to do by writing C++ code that implements the algorithm that solves your problem.
    I understand not possible to have to action using one button of mouse Now I use left button to expands the list of Combobox and right to refresh list of ports.

    Quote Originally Posted by wysota View Post
    Surely there is Rebuild the list whenever you detect a set of available ports is modified.

    Which is the best way. Unfortunately there is no signal which will inform me about it

  11. #31
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Qcombobox

    Quote Originally Posted by arturs View Post
    I understand not possible to have to action using one button of mouse Now I use left button to expands the list of Combobox and right to refresh list of ports.
    That's not what I meant.

    Which is the best way. Unfortunately there is no signal which will inform me about it
    I have no idea how you fetch the list of ports so I cannot suggest a way to refresh that list.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #32

    Default Re: Qcombobox

    Quote Originally Posted by wysota View Post
    That's not what I meant..
    It works After emiting signal receiver refresh list of ports and showlist so I can have many action for one button

    Thank you for your help and for your patience.

    Last question

    Everytime when I receive a data from Qserialport my aplication is closed (after receiving) for a long time and always with error.
    If I do not receive any data then the aplication is closed very fast with code 0

Similar Threads

  1. Replies: 1
    Last Post: 20th May 2015, 11:21
  2. QComboBox
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2014, 14:14
  3. QComboBox
    By kavinsiva in forum Qt Programming
    Replies: 3
    Last Post: 10th August 2009, 16:11
  4. QComboBox
    By bismitapadhy in forum Qt Programming
    Replies: 7
    Last Post: 15th July 2009, 06:01
  5. QComboBox
    By coderbob in forum Qt Programming
    Replies: 4
    Last Post: 12th December 2007, 06:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.