Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to modify QSpinBox appearance

How to modify QSpinBox appearance

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 395 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    viniltc
    wrote on last edited by
    #1

    Hi All,

    I have got a basic question. How to sublcass a Qt object to make some modification in the appearance?

    For ex. I need to modify the standard QSpinBox just with the increment/decrement buttons without the value display:

    d7d49234-77dc-4de4-b5c1-dbd0f422bdf5-image.png

    Even though I came across the keyword "sublcass" an object, I never understood systematic way of doing this. It will be very helpful if someone shows the step-by-step procedure to subclass a standard QSpinBox. I started with the following steps, correct me if I'm wrong

    1. Create a class called customspinbox with base class QSpinBox (include QObject and QWidget).
    2. Did following modifications to the customspinbox class:
    #ifndef CUSTOMSPINBOX_H
    #define CUSTOMSPINBOX_H
    
    #include <QObject>
    #include <QWidget>
    #include <QSpinBox>
    
    class customspinbox : public QSpinBox
    {
      Q_OBJECT
      
    public:
      customspinbox(QWidget *parent =nullptr);
    };
    
    #endif // CUSTOMSPINBOX_H
    
    1. In the mainwindow.ui I added a SpinBox and promoted this to the customspinbox class

    2. I speculate the next step will be to override paintEvent function to delete the textBrowser or similar object which displays the spinbox value. But I don't know how to do this.

    can you show me how to get rid of the display part of the QSpinBox?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Wouldn't it be simpler to create a custom widget with these two buttons ?
      It looks like you are about to make your life more complicated than needed.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved