Results 1 to 7 of 7

Thread: Add signals to qTextEdit

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2017
    Posts
    55
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Add signals to qTextEdit

    I have implemented a 3rd party LED widget called tled. It suggests promoting a qTextEdit widget to tled because of some of the methods that tled needs to inherit from qTextEdit.

    Now, unfortunately I find that I need the ability to click on the promoted LED to initiate some processing. Of course qTextEdit does not emit a clicked() or pressed() signal.

    I guess my only option, if I stick with the qTextEdit is to attach mouse functions to qTextEdit. How do I do that? or can I add a clicked() signal to my LED?

    I am using RHEL6 and Qt4.8.

    Thanks for any help

    emp1953
    Last edited by emp1953; 27th August 2019 at 21:53.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Add signals to qTextEdit

    How about this ?

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Add signals to qTextEdit

    While it sounds very strange that you would use a multi line text input widget as the base for a LED widget, the mechanism to add signals to your class is always the same.

    1) add a "signals" section to the class declaration
    2) add declarations for the signals you want to have
    3) overwrite the protected virtual event handler methods that you want to react to and emit your signals when appropriate

    Cheers,
    _

  4. #4
    Join Date
    Apr 2017
    Posts
    55
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Add signals to qTextEdit

    Quote Originally Posted by anda_skoa View Post
    While it sounds very strange that you would use a multi line text input widget as the base for a LED widget, the mechanism to add signals to your class is always the same.

    1) add a "signals" section to the class declaration
    2) add declarations for the signals you want to have
    3) overwrite the protected virtual event handler methods that you want to react to and emit your signals when appropriate

    Cheers,
    _
    One of the methods that TLED needs to inherit is setValue(). Can you suggest a better widget to promote to that has both setValue() and clicked() or pressed() or mouseReleased() etc.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Add signals to qTextEdit

    Quote Originally Posted by emp1953 View Post
    One of the methods that TLED needs to inherit is setValue().
    This is getting even more weird: QTextEdit does not have a setValue() method.

    Do you mean LED as in Light Emitting Diode? I.e. a control light of sorts?

    Or does that mean something entirely different in your context and which is why you need the capability to display formatted multi line text?

    Quote Originally Posted by emp1953 View Post
    Can you suggest a better widget to promote to that has both setValue() and clicked() or pressed() or mouseReleased() etc.
    All widgets have mousePressed() and mouseReleased() event handlers, these are part of the QWidget API.

    Cheers,
    _

  6. #6
    Join Date
    Apr 2017
    Posts
    55
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Add signals to qTextEdit

    Quote Originally Posted by anda_skoa View Post
    This is getting even more weird: QTextEdit does not have a setValue() method.

    Do you mean LED as in Light Emitting Diode? I.e. a control light of sorts?

    Or does that mean something entirely different in your context and which is why you need the capability to display formatted multi line text?



    All widgets have mousePressed() and mouseReleased() event handlers, these are part of the QWidget API.

    Cheers,
    _

    Light emitting diode.
    When I try to connect mousePressed to a slot I get an error saying that mousePressed is not found.

    Quote Originally Posted by anda_skoa View Post
    This is getting even more weird: QTextEdit does not have a setValue() method.

    Do you mean LED as in Light Emitting Diode? I.e. a control light of sorts?

    Or does that mean something entirely different in your context and which is why you need the capability to display formatted multi line text?



    All widgets have mousePressed() and mouseReleased() event handlers, these are part of the QWidget API.

    Cheers,
    _
    Sorry I misspoke. it is not setValue, it is setText.

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Add signals to qTextEdit

    I have implemented a 3rd party LED widget called tled.
    Isn't your "tled" class already derived from something like QPushButton? It should already have the necessary methods for setting text, etc.

    I think you may be a bit confused between "promoting" a widget that you are using in Qt Designer and "deriving" a widget from some base class that has functionality you want to use. They are totally different concepts.

    In Qt Designer, you can lay out a user interface window (dialog, widget, whatever) and use some suitable widget as a placeholder in the GUI to stand in for a custom widget like your tled widget. After you finish the layout, you tell Qt Designer to "promote" the standard widget you have used to be your custom widget instead. All this does in practice is to update the ui file to replace the class name of the Qt widget with the class name of the custom widget and add some more UI code to import the correct header file for the custom widget when the UIC compiler runs.

    When you want to use Qt Designer promotion and you want to be able to use Qt Designer to set default values for your custom widget, you generally choose a Qt widget that has properties with the same names as those for your custom widget. Qt Designer will create UI code for the stock Qt widget you have chosen that just happens to continue to work after promotion because the custom widget has the same property. Perhaps this is why the authors of your tled widget suggested using QTextEdit as the placeholder before promotion.

    Promotion does not mean that you can magically add new properties to your custom widget by choosing a Qt widget with those properties and then promoting it. Your custom widget is what it is and you can't change it through some UI designer switcheroo.

    What you can do is to derive a new C++ class that uses your custom widget as a base class. You can then add whatever functionality you want to this new class because you're in charge. If you name new properties for this class to be the same as those used by a Qt widget (a "text" property, for example), then you can trick Qt Designer into generating the code to support that property in your new widget by choosing the appropriate Qt widget, setting the property in Designer, then promoting the Qt widget to your new widget. You have not done anything to change the programming interface for either widget. All you have done is to tell Qt Designer, "for the purposes of setting this property value, treat my custom widget as though it was this standard Qt widget instead".

    When I try to connect mousePressed to a slot I get an error saying that mousePressed is not found.
    "mousePressed()" is a Qt widget event, not a signal. You cannot connect events to slots. This will either result in a compiler error or a Qt runtime warning (depending on how the code is written). If you want to handle a mousePressed() event and be able to use that to call a slot method, then the simplest procedure is to derive a new class, add a custom signal (mousePressedSignal() for example), implement an override of the mousePressed() event, and in that handler emit your new signal. Once you have that in place, you can connect this new signal to whatever slot you want.
    Last edited by d_stranz; 28th August 2019 at 18:38.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 6
    Last Post: 21st March 2017, 18:16
  2. Replies: 6
    Last Post: 29th April 2011, 16:22
  3. Replies: 1
    Last Post: 24th October 2010, 12:09
  4. QTextEdit cut copy and paste signals.
    By chris_helloworld in forum Qt Programming
    Replies: 0
    Last Post: 19th October 2010, 12:15
  5. QThread and signals (linux/UNIX signals not Qt Signals)
    By Micawber in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 23:18

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.