Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8115137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:21:59+00:00 2026-06-06T03:21:59+00:00

I have written a custom class for overriding the seek method of QSlider. Basically

  • 0

I have written a custom class for overriding the seek method of QSlider. Basically this class allows seeking on the slider where ever the user clicks .

tbslider.h

#ifndef TBSLIDER_H
#define TBSLIDER_H

#include <QSlider>
#include <QObject>

class Tbslider:  public QSlider
{
    Q_OBJECT
public:
    explicit Tbslider(QWidget *parent=0);

signals:
    void tbJump(int);
protected:
    void mousePressEvent(QMouseEvent *event);
private:
    QSlider *qslider;
};
#endif // TBSLIDER_H

tbslider.cpp

#include <iostream>
#include <QEvent>
#include <QPoint>
#include <QMouseEvent>
#include "tbslider.h"

Tbslider::Tbslider(QWidget *parent):QSlider(parent)
{

}
void Tbslider::mousePressEvent(QMouseEvent *event)
{
QSlider::mousePressEvent(event);

    std::cout<<"\nX co-ordinate"<<event->x();
    std::cout<<"\nY co-ordinate"<<event->y();
    int value =(minimum() + ((maximum()-minimum()) * event->x()) / width() ) ;
    setValue(value);
    emit tbJump(value);
}

Signal and slots in main.cpp

  QApplication app(argc, argv);
  MainWindow player;
  Tbslider tbslider;
  GSTEngine listen
  app.connect(&tbslider, SIGNAL(tbJump(int)), &listen, SLOT(jump(int)));

The above code was supposed to work . Is there anything else I need to do ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:22:01+00:00Added an answer on June 6, 2026 at 3:22 am

    The function should be

    void Tbslider::mousePressEvent(QMouseEvent *event)
    {
    
    
        std::cout<<"\nX co-ordinate"<<event->x();
        std::cout<<"\nY co-ordinate"<<event->y();
        int value =(minimum() + ((maximum()-minimum()) * event->x()) / width() ) ;
        setValue(value);
        emit tbJump(value); 
        QSlider::mousePressEvent(event);
    }
    

    Calling QSlider::mousePressEvent(event) in the beginning resulted in a return statement in the base class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a custom server control which (pseudo-code) looks like public class MyCustomCtrl
I have a custom component called ButtonPanel written in Actionscript. Basically it's just a
Assume i have a custom Windows application written in C#. This application has only
I have written a custom SessionStoreProvider class that inherits from the SessionStateStoreProviderBase. I have
I have written a small custom class to run an audit trail in Lotus
I have a .NET window Service which extend a custom base class, this serves
I have written a custom class that depends significantly on touch dragging/positioning, outside of
I have written a JSP custom tag, implemented in a class that extends TagSupport,
I have a custom class with a serialize method, and I want to be
Basically I have written a custom widget, which is going to be displayed 5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.